<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Source: lib/gridfs/grid_store.js</title>
    
    
    
    
    
    <meta property="og:title" content="MongoDB Driver API for Node.js"/>
    <meta property="og:type" content="website"/>
    <meta property="og:image" content=""/>
    
    <meta property="og:url" content=""/>
    
    <script src="scripts/prettify/prettify.js"></script>
    <script src="scripts/prettify/lang-css.js"></script>
    <script src="scripts/jquery.min.js"></script>
    <!--[if lt IE 9]>
      <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->
    <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
    <link type="text/css" rel="stylesheet" href="styles/bootstrap.min.css">
    <link type="text/css" rel="stylesheet" href="styles/jaguar.css">
    
    
    <script>
    var config = {"monospaceLinks":true,"cleverLinks":true,"default":{"outputSourceFiles":true},"applicationName":"Node.js MongoDB Driver API","googleAnalytics":"UA-7301842-14","openGraph":{"title":"MongoDB Driver API for Node.js","type":"website","image":"","site_name":"","url":""},"meta":{"title":"","description":"","keyword":""},"linenums":true};
    </script>
    

    
    <script>
      (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
      (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
      m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
      })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

      ga('create', UA-7301842-14, 'auto');
      ga('send', 'pageview');
    </script>    
    
</head>
<body>
<div id="wrap" class="clearfix" style="width:100%;">
    <table style="height:100%;width:100%">
        <tr>
            <td valign='top' width="1px">
                
<div class="navigation">
    <h3 class="applicationName"><a href="index.html">Node.js MongoDB Driver API</a></h3>

    <div class="search">
        <input id="search" type="text" class="form-control input-sm" placeholder="Search Documentations">
    </div>
    <ul class="list">
    
        <li class="item" data-name="Admin">
            <span class="title">
                <a href="Admin.html">Admin</a>
                
            </span>
            <ul class="members itemMembers">
            
            </ul>
            <ul class="typedefs itemMembers">
            
            <span class="subtitle">Typedefs</span>
            
                <li data-name="Admin~resultCallback"><a href="Admin.html#~resultCallback">resultCallback</a></li>
            
            </ul>
            <ul class="methods itemMembers">
            
            <span class="subtitle">Methods</span>
            
                <li data-name="Admin#addUser"><a href="Admin.html#addUser">addUser</a></li>
            
                <li data-name="Admin#buildInfo"><a href="Admin.html#buildInfo">buildInfo</a></li>
            
                <li data-name="Admin#command"><a href="Admin.html#command">command</a></li>
            
                <li data-name="Admin#listDatabases"><a href="Admin.html#listDatabases">listDatabases</a></li>
            
                <li data-name="Admin#ping"><a href="Admin.html#ping">ping</a></li>
            
                <li data-name="Admin#removeUser"><a href="Admin.html#removeUser">removeUser</a></li>
            
                <li data-name="Admin#replSetGetStatus"><a href="Admin.html#replSetGetStatus">replSetGetStatus</a></li>
            
                <li data-name="Admin#serverInfo"><a href="Admin.html#serverInfo">serverInfo</a></li>
            
                <li data-name="Admin#serverStatus"><a href="Admin.html#serverStatus">serverStatus</a></li>
            
                <li data-name="Admin#validateCollection"><a href="Admin.html#validateCollection">validateCollection</a></li>
            
            </ul>
            <ul class="events itemMembers">
            
            </ul>
        </li>
    
        <li class="item" data-name="AggregationCursor">
            <span class="title">
                <a href="AggregationCursor.html">AggregationCursor</a>
                
            </span>
            <ul class="members itemMembers">
            
            </ul>
            <ul class="typedefs itemMembers">
            
            <span class="subtitle">Typedefs</span>
            
                <li data-name="AggregationCursor~endCallback"><a href="AggregationCursor.html#~endCallback">endCallback</a></li>
            
                <li data-name="AggregationCursor~iteratorCallback"><a href="AggregationCursor.html#~iteratorCallback">iteratorCallback</a></li>
            
                <li data-name="AggregationCursor~resultCallback"><a href="AggregationCursor.html#~resultCallback">resultCallback</a></li>
            
                <li data-name="AggregationCursor~toArrayResultCallback"><a href="AggregationCursor.html#~toArrayResultCallback">toArrayResultCallback</a></li>
            
            </ul>
            <ul class="methods itemMembers">
            
            <span class="subtitle">Methods</span>
            
                <li data-name="AggregationCursor#batchSize"><a href="AggregationCursor.html#batchSize">batchSize</a></li>
            
                <li data-name="AggregationCursor#clone"><a href="AggregationCursor.html#clone">clone</a></li>
            
                <li data-name="AggregationCursor#close"><a href="AggregationCursor.html#close">close</a></li>
            
                <li data-name="AggregationCursor#each"><a href="AggregationCursor.html#each">each</a></li>
            
                <li data-name="AggregationCursor#explain"><a href="AggregationCursor.html#explain">explain</a></li>
            
                <li data-name="AggregationCursor#geoNear"><a href="AggregationCursor.html#geoNear">geoNear</a></li>
            
                <li data-name="AggregationCursor#group"><a href="AggregationCursor.html#group">group</a></li>
            
                <li data-name="AggregationCursor#hasNext"><a href="AggregationCursor.html#hasNext">hasNext</a></li>
            
                <li data-name="AggregationCursor#isClosed"><a href="AggregationCursor.html#isClosed">isClosed</a></li>
            
                <li data-name="AggregationCursor#limit"><a href="AggregationCursor.html#limit">limit</a></li>
            
                <li data-name="AggregationCursor#lookup"><a href="AggregationCursor.html#lookup">lookup</a></li>
            
                <li data-name="AggregationCursor#match"><a href="AggregationCursor.html#match">match</a></li>
            
                <li data-name="AggregationCursor#maxTimeMS"><a href="AggregationCursor.html#maxTimeMS">maxTimeMS</a></li>
            
                <li data-name="AggregationCursor#next"><a href="AggregationCursor.html#next">next</a></li>
            
                <li data-name="AggregationCursor#out"><a href="AggregationCursor.html#out">out</a></li>
            
                <li data-name="AggregationCursor#pause"><a href="AggregationCursor.html#pause">pause</a></li>
            
                <li data-name="AggregationCursor#pipe"><a href="AggregationCursor.html#pipe">pipe</a></li>
            
                <li data-name="AggregationCursor#project"><a href="AggregationCursor.html#project">project</a></li>
            
                <li data-name="AggregationCursor#read"><a href="AggregationCursor.html#read">read</a></li>
            
                <li data-name="AggregationCursor#redact"><a href="AggregationCursor.html#redact">redact</a></li>
            
                <li data-name="AggregationCursor#resume"><a href="AggregationCursor.html#resume">resume</a></li>
            
                <li data-name="AggregationCursor#rewind"><a href="AggregationCursor.html#rewind">rewind</a></li>
            
                <li data-name="AggregationCursor#setEncoding"><a href="AggregationCursor.html#setEncoding">setEncoding</a></li>
            
                <li data-name="AggregationCursor#skip"><a href="AggregationCursor.html#skip">skip</a></li>
            
                <li data-name="AggregationCursor#sort"><a href="AggregationCursor.html#sort">sort</a></li>
            
                <li data-name="AggregationCursor#toArray"><a href="AggregationCursor.html#toArray">toArray</a></li>
            
                <li data-name="AggregationCursor#unpipe"><a href="AggregationCursor.html#unpipe">unpipe</a></li>
            
                <li data-name="AggregationCursor#unshift"><a href="AggregationCursor.html#unshift">unshift</a></li>
            
                <li data-name="AggregationCursor#unwind"><a href="AggregationCursor.html#unwind">unwind</a></li>
            
                <li data-name="AggregationCursor#wrap"><a href="AggregationCursor.html#wrap">wrap</a></li>
            
            </ul>
            <ul class="events itemMembers">
            
            <span class="subtitle">Events</span>
            
                <li data-name="AggregationCursor#event:close"><a href="AggregationCursor.html#event:close">close</a></li>
            
                <li data-name="AggregationCursor#event:data"><a href="AggregationCursor.html#event:data">data</a></li>
            
                <li data-name="AggregationCursor#event:end"><a href="AggregationCursor.html#event:end">end</a></li>
            
                <li data-name="AggregationCursor#event:readable"><a href="AggregationCursor.html#event:readable">readable</a></li>
            
            </ul>
        </li>
    
        <li class="item" data-name="Binary">
            <span class="title">
                <a href="Binary.html">Binary</a>
                
            </span>
            <ul class="members itemMembers">
            
            <span class="subtitle">Members</span>
            
                <li data-name="Binary.SUBTYPE_BYTE_ARRAY"><a href="Binary.html#.SUBTYPE_BYTE_ARRAY">SUBTYPE_BYTE_ARRAY</a></li>
            
                <li data-name="Binary.SUBTYPE_DEFAULT"><a href="Binary.html#.SUBTYPE_DEFAULT">SUBTYPE_DEFAULT</a></li>
            
                <li data-name="Binary.SUBTYPE_FUNCTION"><a href="Binary.html#.SUBTYPE_FUNCTION">SUBTYPE_FUNCTION</a></li>
            
                <li data-name="Binary.SUBTYPE_MD5"><a href="Binary.html#.SUBTYPE_MD5">SUBTYPE_MD5</a></li>
            
                <li data-name="Binary.SUBTYPE_USER_DEFINED"><a href="Binary.html#.SUBTYPE_USER_DEFINED">SUBTYPE_USER_DEFINED</a></li>
            
                <li data-name="Binary.SUBTYPE_UUID"><a href="Binary.html#.SUBTYPE_UUID">SUBTYPE_UUID</a></li>
            
                <li data-name="Binary.SUBTYPE_UUID_OLD"><a href="Binary.html#.SUBTYPE_UUID_OLD">SUBTYPE_UUID_OLD</a></li>
            
            </ul>
            <ul class="typedefs itemMembers">
            
            </ul>
            <ul class="methods itemMembers">
            
            <span class="subtitle">Methods</span>
            
                <li data-name="Binary#length"><a href="Binary.html#length">length</a></li>
            
                <li data-name="Binary#put"><a href="Binary.html#put">put</a></li>
            
                <li data-name="Binary#read"><a href="Binary.html#read">read</a></li>
            
                <li data-name="Binary#value"><a href="Binary.html#value">value</a></li>
            
                <li data-name="Binary#write"><a href="Binary.html#write">write</a></li>
            
            </ul>
            <ul class="events itemMembers">
            
            </ul>
        </li>
    
        <li class="item" data-name="BSONRegExp">
            <span class="title">
                <a href="BSONRegExp.html">BSONRegExp</a>
                
            </span>
            <ul class="members itemMembers">
            
            </ul>
            <ul class="typedefs itemMembers">
            
            </ul>
            <ul class="methods itemMembers">
            
            </ul>
            <ul class="events itemMembers">
            
            </ul>
        </li>
    
        <li class="item" data-name="BulkOperationBase">
            <span class="title">
                <a href="BulkOperationBase.html">BulkOperationBase</a>
                
            </span>
            <ul class="members itemMembers">
            
            </ul>
            <ul class="typedefs itemMembers">
            
            </ul>
            <ul class="methods itemMembers">
            
            <span class="subtitle">Methods</span>
            
                <li data-name="BulkOperationBase#bulkExecute"><a href="BulkOperationBase.html#bulkExecute">bulkExecute</a></li>
            
                <li data-name="BulkOperationBase#finalOptionsHandler"><a href="BulkOperationBase.html#finalOptionsHandler">finalOptionsHandler</a></li>
            
                <li data-name="BulkOperationBase#find"><a href="BulkOperationBase.html#find">find</a></li>
            
                <li data-name="BulkOperationBase#handleWriteError"><a href="BulkOperationBase.html#handleWriteError">handleWriteError</a></li>
            
                <li data-name="BulkOperationBase#insert"><a href="BulkOperationBase.html#insert">insert</a></li>
            
                <li data-name="BulkOperationBase#raw"><a href="BulkOperationBase.html#raw">raw</a></li>
            
            </ul>
            <ul class="events itemMembers">
            
            </ul>
        </li>
    
        <li class="item" data-name="BulkWriteError">
            <span class="title">
                <a href="BulkWriteError.html">BulkWriteError</a>
                
            </span>
            <ul class="members itemMembers">
            
            </ul>
            <ul class="typedefs itemMembers">
            
            </ul>
            <ul class="methods itemMembers">
            
            </ul>
            <ul class="events itemMembers">
            
            </ul>
        </li>
    
        <li class="item" data-name="BulkWriteResult">
            <span class="title">
                <a href="BulkWriteResult.html">BulkWriteResult</a>
                
            </span>
            <ul class="members itemMembers">
            
            <span class="subtitle">Members</span>
            
                <li data-name="BulkWriteResult#nInserted"><a href="BulkWriteResult.html#nInserted">nInserted</a></li>
            
                <li data-name="BulkWriteResult#nMatched"><a href="BulkWriteResult.html#nMatched">nMatched</a></li>
            
                <li data-name="BulkWriteResult#nModified"><a href="BulkWriteResult.html#nModified">nModified</a></li>
            
                <li data-name="BulkWriteResult#nRemoved"><a href="BulkWriteResult.html#nRemoved">nRemoved</a></li>
            
                <li data-name="BulkWriteResult#nUpserted"><a href="BulkWriteResult.html#nUpserted">nUpserted</a></li>
            
                <li data-name="BulkWriteResult#ok"><a href="BulkWriteResult.html#ok">ok</a></li>
            
            </ul>
            <ul class="typedefs itemMembers">
            
            </ul>
            <ul class="methods itemMembers">
            
            <span class="subtitle">Methods</span>
            
                <li data-name="BulkWriteResult#getInsertedIds"><a href="BulkWriteResult.html#getInsertedIds">getInsertedIds</a></li>
            
                <li data-name="BulkWriteResult#getLastOp"><a href="BulkWriteResult.html#getLastOp">getLastOp</a></li>
            
                <li data-name="BulkWriteResult#getRawResponse"><a href="BulkWriteResult.html#getRawResponse">getRawResponse</a></li>
            
                <li data-name="BulkWriteResult#getUpsertedIdAt"><a href="BulkWriteResult.html#getUpsertedIdAt">getUpsertedIdAt</a></li>
            
                <li data-name="BulkWriteResult#getUpsertedIds"><a href="BulkWriteResult.html#getUpsertedIds">getUpsertedIds</a></li>
            
                <li data-name="BulkWriteResult#getWriteConcernError"><a href="BulkWriteResult.html#getWriteConcernError">getWriteConcernError</a></li>
            
                <li data-name="BulkWriteResult#getWriteErrorAt"><a href="BulkWriteResult.html#getWriteErrorAt">getWriteErrorAt</a></li>
            
                <li data-name="BulkWriteResult#getWriteErrorCount"><a href="BulkWriteResult.html#getWriteErrorCount">getWriteErrorCount</a></li>
            
                <li data-name="BulkWriteResult#getWriteErrors"><a href="BulkWriteResult.html#getWriteErrors">getWriteErrors</a></li>
            
                <li data-name="BulkWriteResult#hasWriteErrors"><a href="BulkWriteResult.html#hasWriteErrors">hasWriteErrors</a></li>
            
                <li data-name="BulkWriteResult#isOk"><a href="BulkWriteResult.html#isOk">isOk</a></li>
            
                <li data-name="BulkWriteResult#toJSON"><a href="BulkWriteResult.html#toJSON">toJSON</a></li>
            
                <li data-name="BulkWriteResult#toString"><a href="BulkWriteResult.html#toString">toString</a></li>
            
            </ul>
            <ul class="events itemMembers">
            
            </ul>
        </li>
    
        <li class="item" data-name="ChangeStream">
            <span class="title">
                <a href="ChangeStream.html">ChangeStream</a>
                
            </span>
            <ul class="members itemMembers">
            
            </ul>
            <ul class="typedefs itemMembers">
            
            <span class="subtitle">Typedefs</span>
            
                <li data-name="ChangeStream~resultCallback"><a href="ChangeStream.html#~resultCallback">resultCallback</a></li>
            
            </ul>
            <ul class="methods itemMembers">
            
            <span class="subtitle">Methods</span>
            
                <li data-name="ChangeStream#close"><a href="ChangeStream.html#close">close</a></li>
            
                <li data-name="ChangeStream#hasNext"><a href="ChangeStream.html#hasNext">hasNext</a></li>
            
                <li data-name="ChangeStream#isClosed"><a href="ChangeStream.html#isClosed">isClosed</a></li>
            
                <li data-name="ChangeStream#next"><a href="ChangeStream.html#next">next</a></li>
            
                <li data-name="ChangeStream#pause"><a href="ChangeStream.html#pause">pause</a></li>
            
                <li data-name="ChangeStream#pipe"><a href="ChangeStream.html#pipe">pipe</a></li>
            
                <li data-name="ChangeStream#resume"><a href="ChangeStream.html#resume">resume</a></li>
            
                <li data-name="ChangeStream#stream"><a href="ChangeStream.html#stream">stream</a></li>
            
                <li data-name="ChangeStream#unpipe"><a href="ChangeStream.html#unpipe">unpipe</a></li>
            
            </ul>
            <ul class="events itemMembers">
            
            <span class="subtitle">Events</span>
            
                <li data-name="ChangeStream#event:change"><a href="ChangeStream.html#event:change">change</a></li>
            
                <li data-name="ChangeStream#event:close"><a href="ChangeStream.html#event:close">close</a></li>
            
                <li data-name="ChangeStream#event:end"><a href="ChangeStream.html#event:end">end</a></li>
            
                <li data-name="ChangeStream#event:error"><a href="ChangeStream.html#event:error">error</a></li>
            
            </ul>
        </li>
    
        <li class="item" data-name="ClientSession">
            <span class="title">
                <a href="ClientSession.html">ClientSession</a>
                
            </span>
            <ul class="members itemMembers">
            
            <span class="subtitle">Members</span>
            
                <li data-name="ClientSession#id"><a href="ClientSession.html#id">id</a></li>
            
            </ul>
            <ul class="typedefs itemMembers">
            
            </ul>
            <ul class="methods itemMembers">
            
            <span class="subtitle">Methods</span>
            
                <li data-name="ClientSession#abortTransaction"><a href="ClientSession.html#abortTransaction">abortTransaction</a></li>
            
                <li data-name="ClientSession#advanceOperationTime"><a href="ClientSession.html#advanceOperationTime">advanceOperationTime</a></li>
            
                <li data-name="ClientSession#commitTransaction"><a href="ClientSession.html#commitTransaction">commitTransaction</a></li>
            
                <li data-name="ClientSession#endSession"><a href="ClientSession.html#endSession">endSession</a></li>
            
                <li data-name="ClientSession#equals"><a href="ClientSession.html#equals">equals</a></li>
            
                <li data-name="ClientSession#incrementTransactionNumber"><a href="ClientSession.html#incrementTransactionNumber">incrementTransactionNumber</a></li>
            
                <li data-name="ClientSession#inTransaction"><a href="ClientSession.html#inTransaction">inTransaction</a></li>
            
                <li data-name="ClientSession#startTransaction"><a href="ClientSession.html#startTransaction">startTransaction</a></li>
            
            </ul>
            <ul class="events itemMembers">
            
            </ul>
        </li>
    
        <li class="item" data-name="Code">
            <span class="title">
                <a href="Code.html">Code</a>
                
            </span>
            <ul class="members itemMembers">
            
            </ul>
            <ul class="typedefs itemMembers">
            
            </ul>
            <ul class="methods itemMembers">
            
            </ul>
            <ul class="events itemMembers">
            
            </ul>
        </li>
    
        <li class="item" data-name="Collection">
            <span class="title">
                <a href="Collection.html">Collection</a>
                
            </span>
            <ul class="members itemMembers">
            
            </ul>
            <ul class="typedefs itemMembers">
            
            <span class="subtitle">Typedefs</span>
            
                <li data-name="Collection~aggregationCallback"><a href="Collection.html#~aggregationCallback">aggregationCallback</a></li>
            
                <li data-name="Collection~bulkWriteOpCallback"><a href="Collection.html#~bulkWriteOpCallback">bulkWriteOpCallback</a></li>
            
                <li data-name="Collection~BulkWriteOpResult"><a href="Collection.html#~BulkWriteOpResult">BulkWriteOpResult</a></li>
            
                <li data-name="Collection~collectionResultCallback"><a href="Collection.html#~collectionResultCallback">collectionResultCallback</a></li>
            
                <li data-name="Collection~countCallback"><a href="Collection.html#~countCallback">countCallback</a></li>
            
                <li data-name="Collection~deleteWriteOpCallback"><a href="Collection.html#~deleteWriteOpCallback">deleteWriteOpCallback</a></li>
            
                <li data-name="Collection~deleteWriteOpResult"><a href="Collection.html#~deleteWriteOpResult">deleteWriteOpResult</a></li>
            
                <li data-name="Collection~findAndModifyCallback"><a href="Collection.html#~findAndModifyCallback">findAndModifyCallback</a></li>
            
                <li data-name="Collection~findAndModifyWriteOpResult"><a href="Collection.html#~findAndModifyWriteOpResult">findAndModifyWriteOpResult</a></li>
            
                <li data-name="Collection~insertOneWriteOpCallback"><a href="Collection.html#~insertOneWriteOpCallback">insertOneWriteOpCallback</a></li>
            
                <li data-name="Collection~insertOneWriteOpResult"><a href="Collection.html#~insertOneWriteOpResult">insertOneWriteOpResult</a></li>
            
                <li data-name="Collection~insertWriteOpCallback"><a href="Collection.html#~insertWriteOpCallback">insertWriteOpCallback</a></li>
            
                <li data-name="Collection~insertWriteOpResult"><a href="Collection.html#~insertWriteOpResult">insertWriteOpResult</a></li>
            
                <li data-name="Collection~parallelCollectionScanCallback"><a href="Collection.html#~parallelCollectionScanCallback">parallelCollectionScanCallback</a></li>
            
                <li data-name="Collection~resultCallback"><a href="Collection.html#~resultCallback">resultCallback</a></li>
            
                <li data-name="Collection~updateWriteOpCallback"><a href="Collection.html#~updateWriteOpCallback">updateWriteOpCallback</a></li>
            
                <li data-name="Collection~updateWriteOpResult"><a href="Collection.html#~updateWriteOpResult">updateWriteOpResult</a></li>
            
                <li data-name="Collection~writeOpCallback"><a href="Collection.html#~writeOpCallback">writeOpCallback</a></li>
            
                <li data-name="Collection~WriteOpResult"><a href="Collection.html#~WriteOpResult">WriteOpResult</a></li>
            
            </ul>
            <ul class="methods itemMembers">
            
            <span class="subtitle">Methods</span>
            
                <li data-name="Collection#aggregate"><a href="Collection.html#aggregate">aggregate</a></li>
            
                <li data-name="Collection#bulkWrite"><a href="Collection.html#bulkWrite">bulkWrite</a></li>
            
                <li data-name="Collection#count"><a href="Collection.html#count">count</a></li>
            
                <li data-name="Collection#countDocuments"><a href="Collection.html#countDocuments">countDocuments</a></li>
            
                <li data-name="Collection#createIndex"><a href="Collection.html#createIndex">createIndex</a></li>
            
                <li data-name="Collection#createIndexes"><a href="Collection.html#createIndexes">createIndexes</a></li>
            
                <li data-name="Collection#deleteMany"><a href="Collection.html#deleteMany">deleteMany</a></li>
            
                <li data-name="Collection#deleteOne"><a href="Collection.html#deleteOne">deleteOne</a></li>
            
                <li data-name="Collection#distinct"><a href="Collection.html#distinct">distinct</a></li>
            
                <li data-name="Collection#drop"><a href="Collection.html#drop">drop</a></li>
            
                <li data-name="Collection#dropAllIndexes"><a href="Collection.html#dropAllIndexes">dropAllIndexes</a></li>
            
                <li data-name="Collection#dropIndex"><a href="Collection.html#dropIndex">dropIndex</a></li>
            
                <li data-name="Collection#dropIndexes"><a href="Collection.html#dropIndexes">dropIndexes</a></li>
            
                <li data-name="Collection#ensureIndex"><a href="Collection.html#ensureIndex">ensureIndex</a></li>
            
                <li data-name="Collection#estimatedDocumentCount"><a href="Collection.html#estimatedDocumentCount">estimatedDocumentCount</a></li>
            
                <li data-name="Collection#find"><a href="Collection.html#find">find</a></li>
            
                <li data-name="Collection#findAndModify"><a href="Collection.html#findAndModify">findAndModify</a></li>
            
                <li data-name="Collection#findAndRemove"><a href="Collection.html#findAndRemove">findAndRemove</a></li>
            
                <li data-name="Collection#findOne"><a href="Collection.html#findOne">findOne</a></li>
            
                <li data-name="Collection#findOneAndDelete"><a href="Collection.html#findOneAndDelete">findOneAndDelete</a></li>
            
                <li data-name="Collection#findOneAndReplace"><a href="Collection.html#findOneAndReplace">findOneAndReplace</a></li>
            
                <li data-name="Collection#findOneAndUpdate"><a href="Collection.html#findOneAndUpdate">findOneAndUpdate</a></li>
            
                <li data-name="Collection#geoHaystackSearch"><a href="Collection.html#geoHaystackSearch">geoHaystackSearch</a></li>
            
                <li data-name="Collection#group"><a href="Collection.html#group">group</a></li>
            
                <li data-name="Collection#indexes"><a href="Collection.html#indexes">indexes</a></li>
            
                <li data-name="Collection#indexExists"><a href="Collection.html#indexExists">indexExists</a></li>
            
                <li data-name="Collection#indexInformation"><a href="Collection.html#indexInformation">indexInformation</a></li>
            
                <li data-name="Collection#initializeOrderedBulkOp"><a href="Collection.html#initializeOrderedBulkOp">initializeOrderedBulkOp</a></li>
            
                <li data-name="Collection#initializeUnorderedBulkOp"><a href="Collection.html#initializeUnorderedBulkOp">initializeUnorderedBulkOp</a></li>
            
                <li data-name="Collection#insert"><a href="Collection.html#insert">insert</a></li>
            
                <li data-name="Collection#insertMany"><a href="Collection.html#insertMany">insertMany</a></li>
            
                <li data-name="Collection#insertOne"><a href="Collection.html#insertOne">insertOne</a></li>
            
                <li data-name="Collection#isCapped"><a href="Collection.html#isCapped">isCapped</a></li>
            
                <li data-name="Collection#listIndexes"><a href="Collection.html#listIndexes">listIndexes</a></li>
            
                <li data-name="Collection#mapReduce"><a href="Collection.html#mapReduce">mapReduce</a></li>
            
                <li data-name="Collection#options"><a href="Collection.html#options">options</a></li>
            
                <li data-name="Collection#parallelCollectionScan"><a href="Collection.html#parallelCollectionScan">parallelCollectionScan</a></li>
            
                <li data-name="Collection#reIndex"><a href="Collection.html#reIndex">reIndex</a></li>
            
                <li data-name="Collection#remove"><a href="Collection.html#remove">remove</a></li>
            
                <li data-name="Collection#rename"><a href="Collection.html#rename">rename</a></li>
            
                <li data-name="Collection#replaceOne"><a href="Collection.html#replaceOne">replaceOne</a></li>
            
                <li data-name="Collection#save"><a href="Collection.html#save">save</a></li>
            
                <li data-name="Collection#stats"><a href="Collection.html#stats">stats</a></li>
            
                <li data-name="Collection#update"><a href="Collection.html#update">update</a></li>
            
                <li data-name="Collection#updateMany"><a href="Collection.html#updateMany">updateMany</a></li>
            
                <li data-name="Collection#updateOne"><a href="Collection.html#updateOne">updateOne</a></li>
            
                <li data-name="Collection#watch"><a href="Collection.html#watch">watch</a></li>
            
            </ul>
            <ul class="events itemMembers">
            
            </ul>
        </li>
    
        <li class="item" data-name="CommandCursor">
            <span class="title">
                <a href="CommandCursor.html">CommandCursor</a>
                
            </span>
            <ul class="members itemMembers">
            
            </ul>
            <ul class="typedefs itemMembers">
            
            <span class="subtitle">Typedefs</span>
            
                <li data-name="CommandCursor~endCallback"><a href="CommandCursor.html#~endCallback">endCallback</a></li>
            
                <li data-name="CommandCursor~iteratorCallback"><a href="CommandCursor.html#~iteratorCallback">iteratorCallback</a></li>
            
                <li data-name="CommandCursor~resultCallback"><a href="CommandCursor.html#~resultCallback">resultCallback</a></li>
            
                <li data-name="CommandCursor~toArrayResultCallback"><a href="CommandCursor.html#~toArrayResultCallback">toArrayResultCallback</a></li>
            
            </ul>
            <ul class="methods itemMembers">
            
            <span class="subtitle">Methods</span>
            
                <li data-name="CommandCursor#batchSize"><a href="CommandCursor.html#batchSize">batchSize</a></li>
            
                <li data-name="CommandCursor#clone"><a href="CommandCursor.html#clone">clone</a></li>
            
                <li data-name="CommandCursor#close"><a href="CommandCursor.html#close">close</a></li>
            
                <li data-name="CommandCursor#each"><a href="CommandCursor.html#each">each</a></li>
            
                <li data-name="CommandCursor#hasNext"><a href="CommandCursor.html#hasNext">hasNext</a></li>
            
                <li data-name="CommandCursor#isClosed"><a href="CommandCursor.html#isClosed">isClosed</a></li>
            
                <li data-name="CommandCursor#maxTimeMS"><a href="CommandCursor.html#maxTimeMS">maxTimeMS</a></li>
            
                <li data-name="CommandCursor#next"><a href="CommandCursor.html#next">next</a></li>
            
                <li data-name="CommandCursor#pause"><a href="CommandCursor.html#pause">pause</a></li>
            
                <li data-name="CommandCursor#pipe"><a href="CommandCursor.html#pipe">pipe</a></li>
            
                <li data-name="CommandCursor#read"><a href="CommandCursor.html#read">read</a></li>
            
                <li data-name="CommandCursor#resume"><a href="CommandCursor.html#resume">resume</a></li>
            
                <li data-name="CommandCursor#rewind"><a href="CommandCursor.html#rewind">rewind</a></li>
            
                <li data-name="CommandCursor#setEncoding"><a href="CommandCursor.html#setEncoding">setEncoding</a></li>
            
                <li data-name="CommandCursor#setReadPreference"><a href="CommandCursor.html#setReadPreference">setReadPreference</a></li>
            
                <li data-name="CommandCursor#toArray"><a href="CommandCursor.html#toArray">toArray</a></li>
            
                <li data-name="CommandCursor#unpipe"><a href="CommandCursor.html#unpipe">unpipe</a></li>
            
                <li data-name="CommandCursor#unshift"><a href="CommandCursor.html#unshift">unshift</a></li>
            
                <li data-name="CommandCursor#wrap"><a href="CommandCursor.html#wrap">wrap</a></li>
            
            </ul>
            <ul class="events itemMembers">
            
            <span class="subtitle">Events</span>
            
                <li data-name="CommandCursor#event:close"><a href="CommandCursor.html#event:close">close</a></li>
            
                <li data-name="CommandCursor#event:data"><a href="CommandCursor.html#event:data">data</a></li>
            
                <li data-name="CommandCursor#event:end"><a href="CommandCursor.html#event:end">end</a></li>
            
                <li data-name="CommandCursor#event:readable"><a href="CommandCursor.html#event:readable">readable</a></li>
            
            </ul>
        </li>
    
        <li class="item" data-name="Cursor">
            <span class="title">
                <a href="Cursor.html">Cursor</a>
                
            </span>
            <ul class="members itemMembers">
            
            </ul>
            <ul class="typedefs itemMembers">
            
            <span class="subtitle">Typedefs</span>
            
                <li data-name="Cursor~countResultCallback"><a href="Cursor.html#~countResultCallback">countResultCallback</a></li>
            
                <li data-name="Cursor~endCallback"><a href="Cursor.html#~endCallback">endCallback</a></li>
            
                <li data-name="Cursor~iteratorCallback"><a href="Cursor.html#~iteratorCallback">iteratorCallback</a></li>
            
                <li data-name="Cursor~resultCallback"><a href="Cursor.html#~resultCallback">resultCallback</a></li>
            
                <li data-name="Cursor~toArrayResultCallback"><a href="Cursor.html#~toArrayResultCallback">toArrayResultCallback</a></li>
            
            </ul>
            <ul class="methods itemMembers">
            
            <span class="subtitle">Methods</span>
            
                <li data-name="Cursor#addCursorFlag"><a href="Cursor.html#addCursorFlag">addCursorFlag</a></li>
            
                <li data-name="Cursor#addQueryModifier"><a href="Cursor.html#addQueryModifier">addQueryModifier</a></li>
            
                <li data-name="Cursor#batchSize"><a href="Cursor.html#batchSize">batchSize</a></li>
            
                <li data-name="Cursor#clone"><a href="Cursor.html#clone">clone</a></li>
            
                <li data-name="Cursor#close"><a href="Cursor.html#close">close</a></li>
            
                <li data-name="Cursor#collation"><a href="Cursor.html#collation">collation</a></li>
            
                <li data-name="Cursor#comment"><a href="Cursor.html#comment">comment</a></li>
            
                <li data-name="Cursor#count"><a href="Cursor.html#count">count</a></li>
            
                <li data-name="Cursor#each"><a href="Cursor.html#each">each</a></li>
            
                <li data-name="Cursor#explain"><a href="Cursor.html#explain">explain</a></li>
            
                <li data-name="Cursor#filter"><a href="Cursor.html#filter">filter</a></li>
            
                <li data-name="Cursor#forEach"><a href="Cursor.html#forEach">forEach</a></li>
            
                <li data-name="Cursor#hasNext"><a href="Cursor.html#hasNext">hasNext</a></li>
            
                <li data-name="Cursor#hint"><a href="Cursor.html#hint">hint</a></li>
            
                <li data-name="Cursor#isClosed"><a href="Cursor.html#isClosed">isClosed</a></li>
            
                <li data-name="Cursor#limit"><a href="Cursor.html#limit">limit</a></li>
            
                <li data-name="Cursor#map"><a href="Cursor.html#map">map</a></li>
            
                <li data-name="Cursor#max"><a href="Cursor.html#max">max</a></li>
            
                <li data-name="Cursor#maxAwaitTimeMS"><a href="Cursor.html#maxAwaitTimeMS">maxAwaitTimeMS</a></li>
            
                <li data-name="Cursor#maxScan"><a href="Cursor.html#maxScan">maxScan</a></li>
            
                <li data-name="Cursor#maxTimeMS"><a href="Cursor.html#maxTimeMS">maxTimeMS</a></li>
            
                <li data-name="Cursor#min"><a href="Cursor.html#min">min</a></li>
            
                <li data-name="Cursor#next"><a href="Cursor.html#next">next</a></li>
            
                <li data-name="Cursor#pause"><a href="Cursor.html#pause">pause</a></li>
            
                <li data-name="Cursor#pipe"><a href="Cursor.html#pipe">pipe</a></li>
            
                <li data-name="Cursor#project"><a href="Cursor.html#project">project</a></li>
            
                <li data-name="Cursor#read"><a href="Cursor.html#read">read</a></li>
            
                <li data-name="Cursor#resume"><a href="Cursor.html#resume">resume</a></li>
            
                <li data-name="Cursor#returnKey"><a href="Cursor.html#returnKey">returnKey</a></li>
            
                <li data-name="Cursor#rewind"><a href="Cursor.html#rewind">rewind</a></li>
            
                <li data-name="Cursor#setCursorOption"><a href="Cursor.html#setCursorOption">setCursorOption</a></li>
            
                <li data-name="Cursor#setEncoding"><a href="Cursor.html#setEncoding">setEncoding</a></li>
            
                <li data-name="Cursor#setReadPreference"><a href="Cursor.html#setReadPreference">setReadPreference</a></li>
            
                <li data-name="Cursor#showRecordId"><a href="Cursor.html#showRecordId">showRecordId</a></li>
            
                <li data-name="Cursor#skip"><a href="Cursor.html#skip">skip</a></li>
            
                <li data-name="Cursor#snapshot"><a href="Cursor.html#snapshot">snapshot</a></li>
            
                <li data-name="Cursor#sort"><a href="Cursor.html#sort">sort</a></li>
            
                <li data-name="Cursor#stream"><a href="Cursor.html#stream">stream</a></li>
            
                <li data-name="Cursor#toArray"><a href="Cursor.html#toArray">toArray</a></li>
            
                <li data-name="Cursor#transformStream"><a href="Cursor.html#transformStream">transformStream</a></li>
            
                <li data-name="Cursor#unpipe"><a href="Cursor.html#unpipe">unpipe</a></li>
            
                <li data-name="Cursor#unshift"><a href="Cursor.html#unshift">unshift</a></li>
            
                <li data-name="Cursor#wrap"><a href="Cursor.html#wrap">wrap</a></li>
            
            </ul>
            <ul class="events itemMembers">
            
            <span class="subtitle">Events</span>
            
                <li data-name="Cursor#event:close"><a href="Cursor.html#event:close">close</a></li>
            
                <li data-name="Cursor#event:data"><a href="Cursor.html#event:data">data</a></li>
            
                <li data-name="Cursor#event:end"><a href="Cursor.html#event:end">end</a></li>
            
                <li data-name="Cursor#event:readable"><a href="Cursor.html#event:readable">readable</a></li>
            
            </ul>
        </li>
    
        <li class="item" data-name="Db">
            <span class="title">
                <a href="Db.html">Db</a>
                
            </span>
            <ul class="members itemMembers">
            
            <span class="subtitle">Members</span>
            
                <li data-name="Db#profilingInfo"><a href="Db.html#profilingInfo">profilingInfo</a></li>
            
            </ul>
            <ul class="typedefs itemMembers">
            
            <span class="subtitle">Typedefs</span>
            
                <li data-name="Db~collectionResultCallback"><a href="Db.html#~collectionResultCallback">collectionResultCallback</a></li>
            
            </ul>
            <ul class="methods itemMembers">
            
            <span class="subtitle">Methods</span>
            
                <li data-name="Db#addUser"><a href="Db.html#addUser">addUser</a></li>
            
                <li data-name="Db#admin"><a href="Db.html#admin">admin</a></li>
            
                <li data-name="Db#collection"><a href="Db.html#collection">collection</a></li>
            
                <li data-name="Db#collections"><a href="Db.html#collections">collections</a></li>
            
                <li data-name="Db#command"><a href="Db.html#command">command</a></li>
            
                <li data-name="Db#createCollection"><a href="Db.html#createCollection">createCollection</a></li>
            
                <li data-name="Db#createIndex"><a href="Db.html#createIndex">createIndex</a></li>
            
                <li data-name="Db#dropCollection"><a href="Db.html#dropCollection">dropCollection</a></li>
            
                <li data-name="Db#dropDatabase"><a href="Db.html#dropDatabase">dropDatabase</a></li>
            
                <li data-name="Db#ensureIndex"><a href="Db.html#ensureIndex">ensureIndex</a></li>
            
                <li data-name="Db#eval"><a href="Db.html#eval">eval</a></li>
            
                <li data-name="Db#executeDbAdminCommand"><a href="Db.html#executeDbAdminCommand">executeDbAdminCommand</a></li>
            
                <li data-name="Db#indexInformation"><a href="Db.html#indexInformation">indexInformation</a></li>
            
                <li data-name="Db#listCollections"><a href="Db.html#listCollections">listCollections</a></li>
            
                <li data-name="Db#profilingLevel"><a href="Db.html#profilingLevel">profilingLevel</a></li>
            
                <li data-name="Db#removeUser"><a href="Db.html#removeUser">removeUser</a></li>
            
                <li data-name="Db#renameCollection"><a href="Db.html#renameCollection">renameCollection</a></li>
            
                <li data-name="Db#setProfilingLevel"><a href="Db.html#setProfilingLevel">setProfilingLevel</a></li>
            
                <li data-name="Db#stats"><a href="Db.html#stats">stats</a></li>
            
                <li data-name="Db#unref"><a href="Db.html#unref">unref</a></li>
            
                <li data-name="Db#watch"><a href="Db.html#watch">watch</a></li>
            
            </ul>
            <ul class="events itemMembers">
            
            <span class="subtitle">Events</span>
            
                <li data-name="Db#event:close"><a href="Db.html#event:close">close</a></li>
            
                <li data-name="Db#event:error"><a href="Db.html#event:error">error</a></li>
            
                <li data-name="Db#event:fullsetup"><a href="Db.html#event:fullsetup">fullsetup</a></li>
            
                <li data-name="Db#event:parseError"><a href="Db.html#event:parseError">parseError</a></li>
            
                <li data-name="Db#event:reconnect"><a href="Db.html#event:reconnect">reconnect</a></li>
            
                <li data-name="Db#event:timeout"><a href="Db.html#event:timeout">timeout</a></li>
            
            </ul>
        </li>
    
        <li class="item" data-name="DBRef">
            <span class="title">
                <a href="DBRef.html">DBRef</a>
                
            </span>
            <ul class="members itemMembers">
            
            </ul>
            <ul class="typedefs itemMembers">
            
            </ul>
            <ul class="methods itemMembers">
            
            </ul>
            <ul class="events itemMembers">
            
            </ul>
        </li>
    
        <li class="item" data-name="Decimal128">
            <span class="title">
                <a href="Decimal128.html">Decimal128</a>
                
            </span>
            <ul class="members itemMembers">
            
            </ul>
            <ul class="typedefs itemMembers">
            
            </ul>
            <ul class="methods itemMembers">
            
            <span class="subtitle">Methods</span>
            
                <li data-name="Decimal128#toString"><a href="Decimal128.html#toString">toString</a></li>
            
                <li data-name="Decimal128.fromString"><a href="Decimal128.html#.fromString">fromString</a></li>
            
            </ul>
            <ul class="events itemMembers">
            
            </ul>
        </li>
    
        <li class="item" data-name="Double">
            <span class="title">
                <a href="Double.html">Double</a>
                
            </span>
            <ul class="members itemMembers">
            
            </ul>
            <ul class="typedefs itemMembers">
            
            </ul>
            <ul class="methods itemMembers">
            
            <span class="subtitle">Methods</span>
            
                <li data-name="Double#valueOf"><a href="Double.html#valueOf">valueOf</a></li>
            
            </ul>
            <ul class="events itemMembers">
            
            </ul>
        </li>
    
        <li class="item" data-name="FindOperators">
            <span class="title">
                <a href="FindOperators.html">FindOperators</a>
                
            </span>
            <ul class="members itemMembers">
            
            </ul>
            <ul class="typedefs itemMembers">
            
            </ul>
            <ul class="methods itemMembers">
            
            <span class="subtitle">Methods</span>
            
                <li data-name="FindOperators#delete"><a href="FindOperators.html#delete">delete</a></li>
            
                <li data-name="FindOperators#deleteOne"><a href="FindOperators.html#deleteOne">deleteOne</a></li>
            
                <li data-name="FindOperators#remove"><a href="FindOperators.html#remove">remove</a></li>
            
                <li data-name="FindOperators#removeOne"><a href="FindOperators.html#removeOne">removeOne</a></li>
            
                <li data-name="FindOperators#replaceOne"><a href="FindOperators.html#replaceOne">replaceOne</a></li>
            
                <li data-name="FindOperators#update"><a href="FindOperators.html#update">update</a></li>
            
                <li data-name="FindOperators#updateOne"><a href="FindOperators.html#updateOne">updateOne</a></li>
            
                <li data-name="FindOperators#upsert"><a href="FindOperators.html#upsert">upsert</a></li>
            
            </ul>
            <ul class="events itemMembers">
            
            </ul>
        </li>
    
        <li class="item" data-name="GridFSBucket">
            <span class="title">
                <a href="GridFSBucket.html">GridFSBucket</a>
                
            </span>
            <ul class="members itemMembers">
            
            </ul>
            <ul class="typedefs itemMembers">
            
            <span class="subtitle">Typedefs</span>
            
                <li data-name="GridFSBucket~errorCallback"><a href="GridFSBucket.html#~errorCallback">errorCallback</a></li>
            
            </ul>
            <ul class="methods itemMembers">
            
            <span class="subtitle">Methods</span>
            
                <li data-name="GridFSBucket#delete"><a href="GridFSBucket.html#delete">delete</a></li>
            
                <li data-name="GridFSBucket#drop"><a href="GridFSBucket.html#drop">drop</a></li>
            
                <li data-name="GridFSBucket#find"><a href="GridFSBucket.html#find">find</a></li>
            
                <li data-name="GridFSBucket#openDownloadStream"><a href="GridFSBucket.html#openDownloadStream">openDownloadStream</a></li>
            
                <li data-name="GridFSBucket#openDownloadStreamByName"><a href="GridFSBucket.html#openDownloadStreamByName">openDownloadStreamByName</a></li>
            
                <li data-name="GridFSBucket#openUploadStream"><a href="GridFSBucket.html#openUploadStream">openUploadStream</a></li>
            
                <li data-name="GridFSBucket#openUploadStreamWithId"><a href="GridFSBucket.html#openUploadStreamWithId">openUploadStreamWithId</a></li>
            
                <li data-name="GridFSBucket#rename"><a href="GridFSBucket.html#rename">rename</a></li>
            
            </ul>
            <ul class="events itemMembers">
            
            <span class="subtitle">Events</span>
            
                <li data-name="GridFSBucket#event:index"><a href="GridFSBucket.html#event:index">index</a></li>
            
            </ul>
        </li>
    
        <li class="item" data-name="GridFSBucketReadStream">
            <span class="title">
                <a href="GridFSBucketReadStream.html">GridFSBucketReadStream</a>
                
            </span>
            <ul class="members itemMembers">
            
            </ul>
            <ul class="typedefs itemMembers">
            
            </ul>
            <ul class="methods itemMembers">
            
            <span class="subtitle">Methods</span>
            
                <li data-name="GridFSBucketReadStream#_read"><a href="GridFSBucketReadStream.html#_read">_read</a></li>
            
                <li data-name="GridFSBucketReadStream#abort"><a href="GridFSBucketReadStream.html#abort">abort</a></li>
            
                <li data-name="GridFSBucketReadStream#end"><a href="GridFSBucketReadStream.html#end">end</a></li>
            
                <li data-name="GridFSBucketReadStream#start"><a href="GridFSBucketReadStream.html#start">start</a></li>
            
            </ul>
            <ul class="events itemMembers">
            
            <span class="subtitle">Events</span>
            
                <li data-name="GridFSBucketReadStream#event:close"><a href="GridFSBucketReadStream.html#event:close">close</a></li>
            
                <li data-name="GridFSBucketReadStream#event:data"><a href="GridFSBucketReadStream.html#event:data">data</a></li>
            
                <li data-name="GridFSBucketReadStream#event:end"><a href="GridFSBucketReadStream.html#event:end">end</a></li>
            
                <li data-name="GridFSBucketReadStream#event:error"><a href="GridFSBucketReadStream.html#event:error">error</a></li>
            
                <li data-name="GridFSBucketReadStream#event:file"><a href="GridFSBucketReadStream.html#event:file">file</a></li>
            
            </ul>
        </li>
    
        <li class="item" data-name="GridFSBucketWriteStream">
            <span class="title">
                <a href="GridFSBucketWriteStream.html">GridFSBucketWriteStream</a>
                
            </span>
            <ul class="members itemMembers">
            
            </ul>
            <ul class="typedefs itemMembers">
            
            </ul>
            <ul class="methods itemMembers">
            
            <span class="subtitle">Methods</span>
            
                <li data-name="GridFSBucketWriteStream#abort"><a href="GridFSBucketWriteStream.html#abort">abort</a></li>
            
                <li data-name="GridFSBucketWriteStream#end"><a href="GridFSBucketWriteStream.html#end">end</a></li>
            
                <li data-name="GridFSBucketWriteStream#write"><a href="GridFSBucketWriteStream.html#write">write</a></li>
            
            </ul>
            <ul class="events itemMembers">
            
            <span class="subtitle">Events</span>
            
                <li data-name="GridFSBucketWriteStream#event:error"><a href="GridFSBucketWriteStream.html#event:error">error</a></li>
            
                <li data-name="GridFSBucketWriteStream#event:finish"><a href="GridFSBucketWriteStream.html#event:finish">finish</a></li>
            
            </ul>
        </li>
    
        <li class="item" data-name="GridStore">
            <span class="title">
                <a href="GridStore.html">GridStore</a>
                
            </span>
            <ul class="members itemMembers">
            
            <span class="subtitle">Members</span>
            
                <li data-name="GridStore.DEFAULT_CONTENT_TYPE"><a href="GridStore.html#.DEFAULT_CONTENT_TYPE">DEFAULT_CONTENT_TYPE</a></li>
            
                <li data-name="GridStore.DEFAULT_ROOT_COLLECTION"><a href="GridStore.html#.DEFAULT_ROOT_COLLECTION">DEFAULT_ROOT_COLLECTION</a></li>
            
                <li data-name="GridStore.IO_SEEK_CUR"><a href="GridStore.html#.IO_SEEK_CUR">IO_SEEK_CUR</a></li>
            
                <li data-name="GridStore.IO_SEEK_END"><a href="GridStore.html#.IO_SEEK_END">IO_SEEK_END</a></li>
            
                <li data-name="GridStore.IO_SEEK_SET"><a href="GridStore.html#.IO_SEEK_SET">IO_SEEK_SET</a></li>
            
            </ul>
            <ul class="typedefs itemMembers">
            
            <span class="subtitle">Typedefs</span>
            
                <li data-name="GridStore~collectionCallback"><a href="GridStore.html#~collectionCallback">collectionCallback</a></li>
            
                <li data-name="GridStore~gridStoreCallback"><a href="GridStore.html#~gridStoreCallback">gridStoreCallback</a></li>
            
                <li data-name="GridStore~openCallback"><a href="GridStore.html#~openCallback">openCallback</a></li>
            
                <li data-name="GridStore~readCallback"><a href="GridStore.html#~readCallback">readCallback</a></li>
            
                <li data-name="GridStore~readlinesCallback"><a href="GridStore.html#~readlinesCallback">readlinesCallback</a></li>
            
                <li data-name="GridStore~resultCallback"><a href="GridStore.html#~resultCallback">resultCallback</a></li>
            
                <li data-name="GridStore~tellCallback"><a href="GridStore.html#~tellCallback">tellCallback</a></li>
            
            </ul>
            <ul class="methods itemMembers">
            
            <span class="subtitle">Methods</span>
            
                <li data-name="GridStore.exist"><a href="GridStore.html#.exist">exist</a></li>
            
                <li data-name="GridStore.list"><a href="GridStore.html#.list">list</a></li>
            
                <li data-name="GridStore.read"><a href="GridStore.html#.read">read</a></li>
            
                <li data-name="GridStore.readlines"><a href="GridStore.html#.readlines">readlines</a></li>
            
                <li data-name="GridStore.unlink"><a href="GridStore.html#.unlink">unlink</a></li>
            
                <li data-name="GridStore#chunkCollection"><a href="GridStore.html#chunkCollection">chunkCollection</a></li>
            
                <li data-name="GridStore#close"><a href="GridStore.html#close">close</a></li>
            
                <li data-name="GridStore#collection"><a href="GridStore.html#collection">collection</a></li>
            
                <li data-name="GridStore#destroy"><a href="GridStore.html#destroy">destroy</a></li>
            
                <li data-name="GridStore#eof"><a href="GridStore.html#eof">eof</a></li>
            
                <li data-name="GridStore#getc"><a href="GridStore.html#getc">getc</a></li>
            
                <li data-name="GridStore#open"><a href="GridStore.html#open">open</a></li>
            
                <li data-name="GridStore#puts"><a href="GridStore.html#puts">puts</a></li>
            
                <li data-name="GridStore#read"><a href="GridStore.html#read">read</a></li>
            
                <li data-name="GridStore#readlines"><a href="GridStore.html#readlines">readlines</a></li>
            
                <li data-name="GridStore#rewind"><a href="GridStore.html#rewind">rewind</a></li>
            
                <li data-name="GridStore#seek"><a href="GridStore.html#seek">seek</a></li>
            
                <li data-name="GridStore#stream"><a href="GridStore.html#stream">stream</a></li>
            
                <li data-name="GridStore#tell"><a href="GridStore.html#tell">tell</a></li>
            
                <li data-name="GridStore#unlink"><a href="GridStore.html#unlink">unlink</a></li>
            
                <li data-name="GridStore#write"><a href="GridStore.html#write">write</a></li>
            
                <li data-name="GridStore#writeFile"><a href="GridStore.html#writeFile">writeFile</a></li>
            
            </ul>
            <ul class="events itemMembers">
            
            </ul>
        </li>
    
        <li class="item" data-name="GridStoreStream">
            <span class="title">
                <a href="GridStoreStream.html">GridStoreStream</a>
                
            </span>
            <ul class="members itemMembers">
            
            </ul>
            <ul class="typedefs itemMembers">
            
            </ul>
            <ul class="methods itemMembers">
            
            <span class="subtitle">Methods</span>
            
                <li data-name="GridStoreStream#end"><a href="GridStoreStream.html#end">end</a></li>
            
                <li data-name="GridStoreStream#pause"><a href="GridStoreStream.html#pause">pause</a></li>
            
                <li data-name="GridStoreStream#pipe"><a href="GridStoreStream.html#pipe">pipe</a></li>
            
                <li data-name="GridStoreStream#read"><a href="GridStoreStream.html#read">read</a></li>
            
                <li data-name="GridStoreStream#resume"><a href="GridStoreStream.html#resume">resume</a></li>
            
                <li data-name="GridStoreStream#setEncoding"><a href="GridStoreStream.html#setEncoding">setEncoding</a></li>
            
                <li data-name="GridStoreStream#unpipe"><a href="GridStoreStream.html#unpipe">unpipe</a></li>
            
                <li data-name="GridStoreStream#unshift"><a href="GridStoreStream.html#unshift">unshift</a></li>
            
                <li data-name="GridStoreStream#wrap"><a href="GridStoreStream.html#wrap">wrap</a></li>
            
                <li data-name="GridStoreStream#write"><a href="GridStoreStream.html#write">write</a></li>
            
            </ul>
            <ul class="events itemMembers">
            
            <span class="subtitle">Events</span>
            
                <li data-name="GridStoreStream#event:close"><a href="GridStoreStream.html#event:close">close</a></li>
            
                <li data-name="GridStoreStream#event:data"><a href="GridStoreStream.html#event:data">data</a></li>
            
                <li data-name="GridStoreStream#event:drain"><a href="GridStoreStream.html#event:drain">drain</a></li>
            
                <li data-name="GridStoreStream#event:end"><a href="GridStoreStream.html#event:end">end</a></li>
            
                <li data-name="GridStoreStream#event:error"><a href="GridStoreStream.html#event:error">error</a></li>
            
                <li data-name="GridStoreStream#event:finish"><a href="GridStoreStream.html#event:finish">finish</a></li>
            
                <li data-name="GridStoreStream#event:pipe"><a href="GridStoreStream.html#event:pipe">pipe</a></li>
            
                <li data-name="GridStoreStream#event:readable"><a href="GridStoreStream.html#event:readable">readable</a></li>
            
                <li data-name="GridStoreStream#event:unpipe"><a href="GridStoreStream.html#event:unpipe">unpipe</a></li>
            
            </ul>
        </li>
    
        <li class="item" data-name="Int32">
            <span class="title">
                <a href="Int32.html">Int32</a>
                
            </span>
            <ul class="members itemMembers">
            
            </ul>
            <ul class="typedefs itemMembers">
            
            </ul>
            <ul class="methods itemMembers">
            
            <span class="subtitle">Methods</span>
            
                <li data-name="Int32#valueOf"><a href="Int32.html#valueOf">valueOf</a></li>
            
            </ul>
            <ul class="events itemMembers">
            
            </ul>
        </li>
    
        <li class="item" data-name="Logger">
            <span class="title">
                <a href="Logger.html">Logger</a>
                
            </span>
            <ul class="members itemMembers">
            
            </ul>
            <ul class="typedefs itemMembers">
            
            </ul>
            <ul class="methods itemMembers">
            
            <span class="subtitle">Methods</span>
            
                <li data-name="Logger.currentLogger"><a href="Logger.html#.currentLogger">currentLogger</a></li>
            
                <li data-name="Logger.filter"><a href="Logger.html#.filter">filter</a></li>
            
                <li data-name="Logger.reset"><a href="Logger.html#.reset">reset</a></li>
            
                <li data-name="Logger.setCurrentLogger"><a href="Logger.html#.setCurrentLogger">setCurrentLogger</a></li>
            
                <li data-name="Logger.setLevel"><a href="Logger.html#.setLevel">setLevel</a></li>
            
                <li data-name="Logger#debug"><a href="Logger.html#debug">debug</a></li>
            
                <li data-name="Logger#error"><a href="Logger.html#error">error</a></li>
            
                <li data-name="Logger#info"><a href="Logger.html#info">info</a></li>
            
                <li data-name="Logger#isDebug"><a href="Logger.html#isDebug">isDebug</a></li>
            
                <li data-name="Logger#isError"><a href="Logger.html#isError">isError</a></li>
            
                <li data-name="Logger#isInfo"><a href="Logger.html#isInfo">isInfo</a></li>
            
                <li data-name="Logger#isWarn"><a href="Logger.html#isWarn">isWarn</a></li>
            
            </ul>
            <ul class="events itemMembers">
            
            </ul>
        </li>
    
        <li class="item" data-name="Long">
            <span class="title">
                <a href="Long.html">Long</a>
                
            </span>
            <ul class="members itemMembers">
            
            <span class="subtitle">Members</span>
            
                <li data-name="Long.MAX_VALUE"><a href="Long.html#.MAX_VALUE">MAX_VALUE</a></li>
            
                <li data-name="Long.MIN_VALUE"><a href="Long.html#.MIN_VALUE">MIN_VALUE</a></li>
            
                <li data-name="Long.NEG_ONE"><a href="Long.html#.NEG_ONE">NEG_ONE</a></li>
            
                <li data-name="Long.ONE"><a href="Long.html#.ONE">ONE</a></li>
            
                <li data-name="Long.ZERO"><a href="Long.html#.ZERO">ZERO</a></li>
            
            </ul>
            <ul class="typedefs itemMembers">
            
            </ul>
            <ul class="methods itemMembers">
            
            <span class="subtitle">Methods</span>
            
                <li data-name="Long.fromBits"><a href="Long.html#.fromBits">fromBits</a></li>
            
                <li data-name="Long.fromInt"><a href="Long.html#.fromInt">fromInt</a></li>
            
                <li data-name="Long.fromNumber"><a href="Long.html#.fromNumber">fromNumber</a></li>
            
                <li data-name="Long.fromString"><a href="Long.html#.fromString">fromString</a></li>
            
                <li data-name="Long#add"><a href="Long.html#add">add</a></li>
            
                <li data-name="Long#and"><a href="Long.html#and">and</a></li>
            
                <li data-name="Long#compare"><a href="Long.html#compare">compare</a></li>
            
                <li data-name="Long#div"><a href="Long.html#div">div</a></li>
            
                <li data-name="Long#equals"><a href="Long.html#equals">equals</a></li>
            
                <li data-name="Long#getHighBits"><a href="Long.html#getHighBits">getHighBits</a></li>
            
                <li data-name="Long#getLowBits"><a href="Long.html#getLowBits">getLowBits</a></li>
            
                <li data-name="Long#getLowBitsUnsigned"><a href="Long.html#getLowBitsUnsigned">getLowBitsUnsigned</a></li>
            
                <li data-name="Long#getNumBitsAbs"><a href="Long.html#getNumBitsAbs">getNumBitsAbs</a></li>
            
                <li data-name="Long#greaterThan"><a href="Long.html#greaterThan">greaterThan</a></li>
            
                <li data-name="Long#greaterThanOrEqual"><a href="Long.html#greaterThanOrEqual">greaterThanOrEqual</a></li>
            
                <li data-name="Long#isNegative"><a href="Long.html#isNegative">isNegative</a></li>
            
                <li data-name="Long#isOdd"><a href="Long.html#isOdd">isOdd</a></li>
            
                <li data-name="Long#isZero"><a href="Long.html#isZero">isZero</a></li>
            
                <li data-name="Long#lessThan"><a href="Long.html#lessThan">lessThan</a></li>
            
                <li data-name="Long#lessThanOrEqual"><a href="Long.html#lessThanOrEqual">lessThanOrEqual</a></li>
            
                <li data-name="Long#modulo"><a href="Long.html#modulo">modulo</a></li>
            
                <li data-name="Long#multiply"><a href="Long.html#multiply">multiply</a></li>
            
                <li data-name="Long#negate"><a href="Long.html#negate">negate</a></li>
            
                <li data-name="Long#not"><a href="Long.html#not">not</a></li>
            
                <li data-name="Long#notEquals"><a href="Long.html#notEquals">notEquals</a></li>
            
                <li data-name="Long#or"><a href="Long.html#or">or</a></li>
            
                <li data-name="Long#shiftLeft"><a href="Long.html#shiftLeft">shiftLeft</a></li>
            
                <li data-name="Long#shiftRight"><a href="Long.html#shiftRight">shiftRight</a></li>
            
                <li data-name="Long#shiftRightUnsigned"><a href="Long.html#shiftRightUnsigned">shiftRightUnsigned</a></li>
            
                <li data-name="Long#subtract"><a href="Long.html#subtract">subtract</a></li>
            
                <li data-name="Long#toInt"><a href="Long.html#toInt">toInt</a></li>
            
                <li data-name="Long#toJSON"><a href="Long.html#toJSON">toJSON</a></li>
            
                <li data-name="Long#toNumber"><a href="Long.html#toNumber">toNumber</a></li>
            
                <li data-name="Long#toString"><a href="Long.html#toString">toString</a></li>
            
                <li data-name="Long#xor"><a href="Long.html#xor">xor</a></li>
            
            </ul>
            <ul class="events itemMembers">
            
            </ul>
        </li>
    
        <li class="item" data-name="MaxKey">
            <span class="title">
                <a href="MaxKey.html">MaxKey</a>
                
            </span>
            <ul class="members itemMembers">
            
            </ul>
            <ul class="typedefs itemMembers">
            
            </ul>
            <ul class="methods itemMembers">
            
            </ul>
            <ul class="events itemMembers">
            
            </ul>
        </li>
    
        <li class="item" data-name="MinKey">
            <span class="title">
                <a href="MinKey.html">MinKey</a>
                
            </span>
            <ul class="members itemMembers">
            
            </ul>
            <ul class="typedefs itemMembers">
            
            </ul>
            <ul class="methods itemMembers">
            
            </ul>
            <ul class="events itemMembers">
            
            </ul>
        </li>
    
        <li class="item" data-name="MongoClient">
            <span class="title">
                <a href="MongoClient.html">MongoClient</a>
                
            </span>
            <ul class="members itemMembers">
            
            </ul>
            <ul class="typedefs itemMembers">
            
            <span class="subtitle">Typedefs</span>
            
                <li data-name="MongoClient~connectCallback"><a href="MongoClient.html#~connectCallback">connectCallback</a></li>
            
            </ul>
            <ul class="methods itemMembers">
            
            <span class="subtitle">Methods</span>
            
                <li data-name="MongoClient.connect"><a href="MongoClient.html#.connect">connect</a></li>
            
                <li data-name="MongoClient#close"><a href="MongoClient.html#close">close</a></li>
            
                <li data-name="MongoClient#connect"><a href="MongoClient.html#connect">connect</a></li>
            
                <li data-name="MongoClient#db"><a href="MongoClient.html#db">db</a></li>
            
                <li data-name="MongoClient#isConnected"><a href="MongoClient.html#isConnected">isConnected</a></li>
            
                <li data-name="MongoClient#logout"><a href="MongoClient.html#logout">logout</a></li>
            
                <li data-name="MongoClient#startSession"><a href="MongoClient.html#startSession">startSession</a></li>
            
                <li data-name="MongoClient#watch"><a href="MongoClient.html#watch">watch</a></li>
            
                <li data-name="MongoClient#withSession"><a href="MongoClient.html#withSession">withSession</a></li>
            
            </ul>
            <ul class="events itemMembers">
            
            </ul>
        </li>
    
        <li class="item" data-name="MongoError">
            <span class="title">
                <a href="MongoError.html">MongoError</a>
                
            </span>
            <ul class="members itemMembers">
            
            </ul>
            <ul class="typedefs itemMembers">
            
            </ul>
            <ul class="methods itemMembers">
            
            <span class="subtitle">Methods</span>
            
                <li data-name="MongoError.create"><a href="MongoError.html#.create">create</a></li>
            
            </ul>
            <ul class="events itemMembers">
            
            </ul>
        </li>
    
        <li class="item" data-name="MongoNetworkError">
            <span class="title">
                <a href="MongoNetworkError.html">MongoNetworkError</a>
                
            </span>
            <ul class="members itemMembers">
            
            </ul>
            <ul class="typedefs itemMembers">
            
            </ul>
            <ul class="methods itemMembers">
            
            </ul>
            <ul class="events itemMembers">
            
            </ul>
        </li>
    
        <li class="item" data-name="MongoParseError">
            <span class="title">
                <a href="MongoParseError.html">MongoParseError</a>
                
            </span>
            <ul class="members itemMembers">
            
            </ul>
            <ul class="typedefs itemMembers">
            
            </ul>
            <ul class="methods itemMembers">
            
            </ul>
            <ul class="events itemMembers">
            
            </ul>
        </li>
    
        <li class="item" data-name="Mongos">
            <span class="title">
                <a href="Mongos.html">Mongos</a>
                
            </span>
            <ul class="members itemMembers">
            
            </ul>
            <ul class="typedefs itemMembers">
            
            </ul>
            <ul class="methods itemMembers">
            
            </ul>
            <ul class="events itemMembers">
            
            <span class="subtitle">Events</span>
            
                <li data-name="Mongos#event:close"><a href="Mongos.html#event:close">close</a></li>
            
                <li data-name="Mongos#event:commandFailed"><a href="Mongos.html#event:commandFailed">commandFailed</a></li>
            
                <li data-name="Mongos#event:commandStarted"><a href="Mongos.html#event:commandStarted">commandStarted</a></li>
            
                <li data-name="Mongos#event:commandSucceeded"><a href="Mongos.html#event:commandSucceeded">commandSucceeded</a></li>
            
                <li data-name="Mongos#event:connect"><a href="Mongos.html#event:connect">connect</a></li>
            
                <li data-name="Mongos#event:error"><a href="Mongos.html#event:error">error</a></li>
            
                <li data-name="Mongos#event:fullsetup"><a href="Mongos.html#event:fullsetup">fullsetup</a></li>
            
                <li data-name="Mongos#event:ha"><a href="Mongos.html#event:ha">ha</a></li>
            
                <li data-name="Mongos#event:joined"><a href="Mongos.html#event:joined">joined</a></li>
            
                <li data-name="Mongos#event:left"><a href="Mongos.html#event:left">left</a></li>
            
                <li data-name="Mongos#event:open"><a href="Mongos.html#event:open">open</a></li>
            
                <li data-name="Mongos#event:parseError"><a href="Mongos.html#event:parseError">parseError</a></li>
            
                <li data-name="Mongos#event:timeout"><a href="Mongos.html#event:timeout">timeout</a></li>
            
            </ul>
        </li>
    
        <li class="item" data-name="MongoTimeoutError">
            <span class="title">
                <a href="MongoTimeoutError.html">MongoTimeoutError</a>
                
            </span>
            <ul class="members itemMembers">
            
            </ul>
            <ul class="typedefs itemMembers">
            
            </ul>
            <ul class="methods itemMembers">
            
            </ul>
            <ul class="events itemMembers">
            
            </ul>
        </li>
    
        <li class="item" data-name="MongoWriteConcernError">
            <span class="title">
                <a href="MongoWriteConcernError.html">MongoWriteConcernError</a>
                
            </span>
            <ul class="members itemMembers">
            
            </ul>
            <ul class="typedefs itemMembers">
            
            </ul>
            <ul class="methods itemMembers">
            
            </ul>
            <ul class="events itemMembers">
            
            </ul>
        </li>
    
        <li class="item" data-name="ObjectID">
            <span class="title">
                <a href="ObjectID.html">ObjectID</a>
                
            </span>
            <ul class="members itemMembers">
            
            </ul>
            <ul class="typedefs itemMembers">
            
            </ul>
            <ul class="methods itemMembers">
            
            <span class="subtitle">Methods</span>
            
                <li data-name="ObjectID.createFromHexString"><a href="ObjectID.html#.createFromHexString">createFromHexString</a></li>
            
                <li data-name="ObjectID.createFromTime"><a href="ObjectID.html#.createFromTime">createFromTime</a></li>
            
                <li data-name="ObjectID.isValid"><a href="ObjectID.html#.isValid">isValid</a></li>
            
                <li data-name="ObjectID#equals"><a href="ObjectID.html#equals">equals</a></li>
            
                <li data-name="ObjectID#generate"><a href="ObjectID.html#generate">generate</a></li>
            
                <li data-name="ObjectID#getTimestamp"><a href="ObjectID.html#getTimestamp">getTimestamp</a></li>
            
                <li data-name="ObjectID#toHexString"><a href="ObjectID.html#toHexString">toHexString</a></li>
            
            </ul>
            <ul class="events itemMembers">
            
            </ul>
        </li>
    
        <li class="item" data-name="OrderedBulkOperation">
            <span class="title">
                <a href="OrderedBulkOperation.html">OrderedBulkOperation</a>
                
            </span>
            <ul class="members itemMembers">
            
            </ul>
            <ul class="typedefs itemMembers">
            
            <span class="subtitle">Typedefs</span>
            
                <li data-name="OrderedBulkOperation~resultCallback"><a href="OrderedBulkOperation.html#~resultCallback">resultCallback</a></li>
            
            </ul>
            <ul class="methods itemMembers">
            
            <span class="subtitle">Methods</span>
            
                <li data-name="OrderedBulkOperation#execute"><a href="OrderedBulkOperation.html#execute">execute</a></li>
            
            </ul>
            <ul class="events itemMembers">
            
            </ul>
        </li>
    
        <li class="item" data-name="ReplSet">
            <span class="title">
                <a href="ReplSet.html">ReplSet</a>
                
            </span>
            <ul class="members itemMembers">
            
            </ul>
            <ul class="typedefs itemMembers">
            
            </ul>
            <ul class="methods itemMembers">
            
            </ul>
            <ul class="events itemMembers">
            
            <span class="subtitle">Events</span>
            
                <li data-name="ReplSet#event:close"><a href="ReplSet.html#event:close">close</a></li>
            
                <li data-name="ReplSet#event:commandFailed"><a href="ReplSet.html#event:commandFailed">commandFailed</a></li>
            
                <li data-name="ReplSet#event:commandStarted"><a href="ReplSet.html#event:commandStarted">commandStarted</a></li>
            
                <li data-name="ReplSet#event:commandSucceeded"><a href="ReplSet.html#event:commandSucceeded">commandSucceeded</a></li>
            
                <li data-name="ReplSet#event:connect"><a href="ReplSet.html#event:connect">connect</a></li>
            
                <li data-name="ReplSet#event:error"><a href="ReplSet.html#event:error">error</a></li>
            
                <li data-name="ReplSet#event:fullsetup"><a href="ReplSet.html#event:fullsetup">fullsetup</a></li>
            
                <li data-name="ReplSet#event:ha"><a href="ReplSet.html#event:ha">ha</a></li>
            
                <li data-name="ReplSet#event:joined"><a href="ReplSet.html#event:joined">joined</a></li>
            
                <li data-name="ReplSet#event:left"><a href="ReplSet.html#event:left">left</a></li>
            
                <li data-name="ReplSet#event:open"><a href="ReplSet.html#event:open">open</a></li>
            
                <li data-name="ReplSet#event:parseError"><a href="ReplSet.html#event:parseError">parseError</a></li>
            
                <li data-name="ReplSet#event:timeout"><a href="ReplSet.html#event:timeout">timeout</a></li>
            
            </ul>
        </li>
    
        <li class="item" data-name="Server">
            <span class="title">
                <a href="Server.html">Server</a>
                
            </span>
            <ul class="members itemMembers">
            
            </ul>
            <ul class="typedefs itemMembers">
            
            </ul>
            <ul class="methods itemMembers">
            
            </ul>
            <ul class="events itemMembers">
            
            <span class="subtitle">Events</span>
            
                <li data-name="Server#event:close"><a href="Server.html#event:close">close</a></li>
            
                <li data-name="Server#event:commandFailed"><a href="Server.html#event:commandFailed">commandFailed</a></li>
            
                <li data-name="Server#event:commandStarted"><a href="Server.html#event:commandStarted">commandStarted</a></li>
            
                <li data-name="Server#event:commandSucceeded"><a href="Server.html#event:commandSucceeded">commandSucceeded</a></li>
            
                <li data-name="Server#event:connect"><a href="Server.html#event:connect">connect</a></li>
            
                <li data-name="Server#event:error"><a href="Server.html#event:error">error</a></li>
            
                <li data-name="Server#event:parseError"><a href="Server.html#event:parseError">parseError</a></li>
            
                <li data-name="Server#event:reconnect"><a href="Server.html#event:reconnect">reconnect</a></li>
            
                <li data-name="Server#event:timeout"><a href="Server.html#event:timeout">timeout</a></li>
            
            </ul>
        </li>
    
        <li class="item" data-name="Symbol">
            <span class="title">
                <a href="Symbol.html">Symbol</a>
                
            </span>
            <ul class="members itemMembers">
            
            </ul>
            <ul class="typedefs itemMembers">
            
            </ul>
            <ul class="methods itemMembers">
            
            <span class="subtitle">Methods</span>
            
                <li data-name="Symbol#valueOf"><a href="Symbol.html#valueOf">valueOf</a></li>
            
            </ul>
            <ul class="events itemMembers">
            
            </ul>
        </li>
    
        <li class="item" data-name="Timestamp">
            <span class="title">
                <a href="Timestamp.html">Timestamp</a>
                
            </span>
            <ul class="members itemMembers">
            
            <span class="subtitle">Members</span>
            
                <li data-name="Timestamp.MAX_VALUE"><a href="Timestamp.html#.MAX_VALUE">MAX_VALUE</a></li>
            
                <li data-name="Timestamp.MIN_VALUE"><a href="Timestamp.html#.MIN_VALUE">MIN_VALUE</a></li>
            
                <li data-name="Timestamp.NEG_ONE"><a href="Timestamp.html#.NEG_ONE">NEG_ONE</a></li>
            
                <li data-name="Timestamp.ONE"><a href="Timestamp.html#.ONE">ONE</a></li>
            
                <li data-name="Timestamp.ZERO"><a href="Timestamp.html#.ZERO">ZERO</a></li>
            
            </ul>
            <ul class="typedefs itemMembers">
            
            </ul>
            <ul class="methods itemMembers">
            
            <span class="subtitle">Methods</span>
            
                <li data-name="Timestamp.fromBits"><a href="Timestamp.html#.fromBits">fromBits</a></li>
            
                <li data-name="Timestamp.fromInt"><a href="Timestamp.html#.fromInt">fromInt</a></li>
            
                <li data-name="Timestamp.fromNumber"><a href="Timestamp.html#.fromNumber">fromNumber</a></li>
            
                <li data-name="Timestamp.fromString"><a href="Timestamp.html#.fromString">fromString</a></li>
            
                <li data-name="Timestamp#add"><a href="Timestamp.html#add">add</a></li>
            
                <li data-name="Timestamp#and"><a href="Timestamp.html#and">and</a></li>
            
                <li data-name="Timestamp#compare"><a href="Timestamp.html#compare">compare</a></li>
            
                <li data-name="Timestamp#div"><a href="Timestamp.html#div">div</a></li>
            
                <li data-name="Timestamp#equals"><a href="Timestamp.html#equals">equals</a></li>
            
                <li data-name="Timestamp#getHighBits"><a href="Timestamp.html#getHighBits">getHighBits</a></li>
            
                <li data-name="Timestamp#getLowBits"><a href="Timestamp.html#getLowBits">getLowBits</a></li>
            
                <li data-name="Timestamp#getLowBitsUnsigned"><a href="Timestamp.html#getLowBitsUnsigned">getLowBitsUnsigned</a></li>
            
                <li data-name="Timestamp#getNumBitsAbs"><a href="Timestamp.html#getNumBitsAbs">getNumBitsAbs</a></li>
            
                <li data-name="Timestamp#greaterThan"><a href="Timestamp.html#greaterThan">greaterThan</a></li>
            
                <li data-name="Timestamp#greaterThanOrEqual"><a href="Timestamp.html#greaterThanOrEqual">greaterThanOrEqual</a></li>
            
                <li data-name="Timestamp#isNegative"><a href="Timestamp.html#isNegative">isNegative</a></li>
            
                <li data-name="Timestamp#isOdd"><a href="Timestamp.html#isOdd">isOdd</a></li>
            
                <li data-name="Timestamp#isZero"><a href="Timestamp.html#isZero">isZero</a></li>
            
                <li data-name="Timestamp#lessThan"><a href="Timestamp.html#lessThan">lessThan</a></li>
            
                <li data-name="Timestamp#lessThanOrEqual"><a href="Timestamp.html#lessThanOrEqual">lessThanOrEqual</a></li>
            
                <li data-name="Timestamp#modulo"><a href="Timestamp.html#modulo">modulo</a></li>
            
                <li data-name="Timestamp#multiply"><a href="Timestamp.html#multiply">multiply</a></li>
            
                <li data-name="Timestamp#negate"><a href="Timestamp.html#negate">negate</a></li>
            
                <li data-name="Timestamp#not"><a href="Timestamp.html#not">not</a></li>
            
                <li data-name="Timestamp#notEquals"><a href="Timestamp.html#notEquals">notEquals</a></li>
            
                <li data-name="Timestamp#or"><a href="Timestamp.html#or">or</a></li>
            
                <li data-name="Timestamp#shiftLeft"><a href="Timestamp.html#shiftLeft">shiftLeft</a></li>
            
                <li data-name="Timestamp#shiftRight"><a href="Timestamp.html#shiftRight">shiftRight</a></li>
            
                <li data-name="Timestamp#shiftRightUnsigned"><a href="Timestamp.html#shiftRightUnsigned">shiftRightUnsigned</a></li>
            
                <li data-name="Timestamp#subtract"><a href="Timestamp.html#subtract">subtract</a></li>
            
                <li data-name="Timestamp#toInt"><a href="Timestamp.html#toInt">toInt</a></li>
            
                <li data-name="Timestamp#toJSON"><a href="Timestamp.html#toJSON">toJSON</a></li>
            
                <li data-name="Timestamp#toNumber"><a href="Timestamp.html#toNumber">toNumber</a></li>
            
                <li data-name="Timestamp#toString"><a href="Timestamp.html#toString">toString</a></li>
            
                <li data-name="Timestamp#xor"><a href="Timestamp.html#xor">xor</a></li>
            
            </ul>
            <ul class="events itemMembers">
            
            </ul>
        </li>
    
        <li class="item" data-name="UnorderedBulkOperation">
            <span class="title">
                <a href="UnorderedBulkOperation.html">UnorderedBulkOperation</a>
                
            </span>
            <ul class="members itemMembers">
            
            </ul>
            <ul class="typedefs itemMembers">
            
            <span class="subtitle">Typedefs</span>
            
                <li data-name="UnorderedBulkOperation~resultCallback"><a href="UnorderedBulkOperation.html#~resultCallback">resultCallback</a></li>
            
            </ul>
            <ul class="methods itemMembers">
            
            <span class="subtitle">Methods</span>
            
                <li data-name="UnorderedBulkOperation#execute"><a href="UnorderedBulkOperation.html#execute">execute</a></li>
            
            </ul>
            <ul class="events itemMembers">
            
            </ul>
        </li>
    
        <li class="item" data-name="WriteConcernError">
            <span class="title">
                <a href="WriteConcernError.html">WriteConcernError</a>
                
            </span>
            <ul class="members itemMembers">
            
            <span class="subtitle">Members</span>
            
                <li data-name="WriteConcernError#code"><a href="WriteConcernError.html#code">code</a></li>
            
                <li data-name="WriteConcernError#errmsg"><a href="WriteConcernError.html#errmsg">errmsg</a></li>
            
            </ul>
            <ul class="typedefs itemMembers">
            
            </ul>
            <ul class="methods itemMembers">
            
            <span class="subtitle">Methods</span>
            
                <li data-name="WriteConcernError#toJSON"><a href="WriteConcernError.html#toJSON">toJSON</a></li>
            
                <li data-name="WriteConcernError#toString"><a href="WriteConcernError.html#toString">toString</a></li>
            
            </ul>
            <ul class="events itemMembers">
            
            </ul>
        </li>
    
        <li class="item" data-name="WriteError">
            <span class="title">
                <a href="WriteError.html">WriteError</a>
                
            </span>
            <ul class="members itemMembers">
            
            <span class="subtitle">Members</span>
            
                <li data-name="WriteError#code"><a href="WriteError.html#code">code</a></li>
            
                <li data-name="WriteError#errmsg"><a href="WriteError.html#errmsg">errmsg</a></li>
            
                <li data-name="WriteError#index"><a href="WriteError.html#index">index</a></li>
            
            </ul>
            <ul class="typedefs itemMembers">
            
            </ul>
            <ul class="methods itemMembers">
            
            <span class="subtitle">Methods</span>
            
                <li data-name="WriteError#getOperation"><a href="WriteError.html#getOperation">getOperation</a></li>
            
                <li data-name="WriteError#toJSON"><a href="WriteError.html#toJSON">toJSON</a></li>
            
                <li data-name="WriteError#toString"><a href="WriteError.html#toString">toString</a></li>
            
            </ul>
            <ul class="events itemMembers">
            
            </ul>
        </li>
    
    </ul>
</div>
            </td>
            <td valign='top'>        
                <div class="main">
                    <h1 class="page-title" data-filename="lib_gridfs_grid_store.js.html">Source: lib/gridfs/grid_store.js</h1>
                    


    
    <section>
        <article>
            <pre class="prettyprint source linenums"><code>'use strict';

/**
 * @fileOverview GridFS is a tool for MongoDB to store files to the database.
 * Because of the restrictions of the object size the database can hold, a
 * facility to split a file into several chunks is needed. The {@link GridStore}
 * class offers a simplified api to interact with files while managing the
 * chunks of split files behind the scenes. More information about GridFS can be
 * found &lt;a href="http://www.mongodb.org/display/DOCS/GridFS">here&lt;/a>.
 *
 * @example
 * const MongoClient = require('mongodb').MongoClient;
 * const GridStore = require('mongodb').GridStore;
 * const ObjectID = require('mongodb').ObjectID;
 * const test = require('assert');
 * // Connection url
 * const url = 'mongodb://localhost:27017';
 * // Database Name
 * const dbName = 'test';
 * // Connect using MongoClient
 * MongoClient.connect(url, function(err, client) {
 *   const db = client.db(dbName);
 *   const gridStore = new GridStore(db, null, "w");
 *   gridStore.open(function(err, gridStore) {
 *     gridStore.write("hello world!", function(err, gridStore) {
 *       gridStore.close(function(err, result) {
 *         // Let's read the file using object Id
 *         GridStore.read(db, result._id, function(err, data) {
 *           test.equal('hello world!', data);
 *           client.close();
 *           test.done();
 *         });
 *       });
 *     });
 *   });
 * });
 */
const Chunk = require('./chunk');
const ObjectID = require('mongodb-core').BSON.ObjectID;
const ReadPreference = require('mongodb-core').ReadPreference;
const Buffer = require('safe-buffer').Buffer;
const fs = require('fs');
const f = require('util').format;
const util = require('util');
const MongoError = require('mongodb-core').MongoError;
const inherits = util.inherits;
const Duplex = require('stream').Duplex;
const shallowClone = require('../utils').shallowClone;
const executeOperation = require('../utils').executeOperation;
const deprecate = require('util').deprecate;

var REFERENCE_BY_FILENAME = 0,
  REFERENCE_BY_ID = 1;

const deprecationFn = deprecate(() => {},
'GridStore is deprecated, and will be removed in a future version. Please use GridFSBucket instead');

/**
 * Namespace provided by the mongodb-core and node.js
 * @external Duplex
 */

/**
 * Create a new GridStore instance
 *
 * Modes
 *  - **"r"** - read only. This is the default mode.
 *  - **"w"** - write in truncate mode. Existing data will be overwriten.
 *
 * @class
 * @param {Db} db A database instance to interact with.
 * @param {object} [id] optional unique id for this file
 * @param {string} [filename] optional filename for this file, no unique constrain on the field
 * @param {string} mode set the mode for this file.
 * @param {object} [options] Optional settings.
 * @param {(number|string)} [options.w] The write concern.
 * @param {number} [options.wtimeout] The write concern timeout.
 * @param {boolean} [options.j=false] Specify a journal write concern.
 * @param {boolean} [options.fsync=false] Specify a file sync write concern.
 * @param {string} [options.root] Root collection to use. Defaults to **{GridStore.DEFAULT_ROOT_COLLECTION}**.
 * @param {string} [options.content_type] MIME type of the file. Defaults to **{GridStore.DEFAULT_CONTENT_TYPE}**.
 * @param {number} [options.chunk_size=261120] Size for the chunk. Defaults to **{Chunk.DEFAULT_CHUNK_SIZE}**.
 * @param {object} [options.metadata] Arbitrary data the user wants to store.
 * @param {object} [options.promiseLibrary] A Promise library class the application wishes to use such as Bluebird, must be ES6 compatible
 * @param {(ReadPreference|string)} [options.readPreference] The preferred read preference (ReadPreference.PRIMARY, ReadPreference.PRIMARY_PREFERRED, ReadPreference.SECONDARY, ReadPreference.SECONDARY_PREFERRED, ReadPreference.NEAREST).
 * @property {number} chunkSize Get the gridstore chunk size.
 * @property {number} md5 The md5 checksum for this file.
 * @property {number} chunkNumber The current chunk number the gridstore has materialized into memory
 * @return {GridStore} a GridStore instance.
 * @deprecated Use GridFSBucket API instead
 */
var GridStore = function GridStore(db, id, filename, mode, options) {
  deprecationFn();
  if (!(this instanceof GridStore)) return new GridStore(db, id, filename, mode, options);
  this.db = db;

  // Handle options
  if (typeof options === 'undefined') options = {};
  // Handle mode
  if (typeof mode === 'undefined') {
    mode = filename;
    filename = undefined;
  } else if (typeof mode === 'object') {
    options = mode;
    mode = filename;
    filename = undefined;
  }

  if (id &amp;&amp; id._bsontype === 'ObjectID') {
    this.referenceBy = REFERENCE_BY_ID;
    this.fileId = id;
    this.filename = filename;
  } else if (typeof filename === 'undefined') {
    this.referenceBy = REFERENCE_BY_FILENAME;
    this.filename = id;
    if (mode.indexOf('w') != null) {
      this.fileId = new ObjectID();
    }
  } else {
    this.referenceBy = REFERENCE_BY_ID;
    this.fileId = id;
    this.filename = filename;
  }

  // Set up the rest
  this.mode = mode == null ? 'r' : mode;
  this.options = options || {};

  // Opened
  this.isOpen = false;

  // Set the root if overridden
  this.root =
    this.options['root'] == null ? GridStore.DEFAULT_ROOT_COLLECTION : this.options['root'];
  this.position = 0;
  this.readPreference =
    this.options.readPreference || db.options.readPreference || ReadPreference.primary;
  this.writeConcern = _getWriteConcern(db, this.options);
  // Set default chunk size
  this.internalChunkSize =
    this.options['chunkSize'] == null ? Chunk.DEFAULT_CHUNK_SIZE : this.options['chunkSize'];

  // Get the promiseLibrary
  var promiseLibrary = this.options.promiseLibrary || Promise;

  // Set the promiseLibrary
  this.promiseLibrary = promiseLibrary;

  Object.defineProperty(this, 'chunkSize', {
    enumerable: true,
    get: function() {
      return this.internalChunkSize;
    },
    set: function(value) {
      if (!(this.mode[0] === 'w' &amp;&amp; this.position === 0 &amp;&amp; this.uploadDate == null)) {
        this.internalChunkSize = this.internalChunkSize;
      } else {
        this.internalChunkSize = value;
      }
    }
  });

  Object.defineProperty(this, 'md5', {
    enumerable: true,
    get: function() {
      return this.internalMd5;
    }
  });

  Object.defineProperty(this, 'chunkNumber', {
    enumerable: true,
    get: function() {
      return this.currentChunk &amp;&amp; this.currentChunk.chunkNumber
        ? this.currentChunk.chunkNumber
        : null;
    }
  });
};

/**
 * The callback format for the Gridstore.open method
 * @callback GridStore~openCallback
 * @param {MongoError} error An error instance representing the error during the execution.
 * @param {GridStore} gridStore The GridStore instance if the open method was successful.
 */

/**
 * Opens the file from the database and initialize this object. Also creates a
 * new one if file does not exist.
 *
 * @method
 * @param {object} [options] Optional settings
 * @param {ClientSession} [options.session] optional session to use for this operation
 * @param {GridStore~openCallback} [callback] this will be called after executing this method
 * @return {Promise} returns Promise if no callback passed
 * @deprecated Use GridFSBucket API instead
 */
GridStore.prototype.open = function(options, callback) {
  if (typeof options === 'function') (callback = options), (options = {});
  options = options || {};

  if (this.mode !== 'w' &amp;&amp; this.mode !== 'w+' &amp;&amp; this.mode !== 'r') {
    throw MongoError.create({ message: 'Illegal mode ' + this.mode, driver: true });
  }

  return executeOperation(this.db.s.topology, open, [this, options, callback], {
    skipSessions: true
  });
};

var open = function(self, options, callback) {
  // Get the write concern
  var writeConcern = _getWriteConcern(self.db, self.options);

  // If we are writing we need to ensure we have the right indexes for md5's
  if (self.mode === 'w' || self.mode === 'w+') {
    // Get files collection
    var collection = self.collection();
    // Put index on filename
    collection.ensureIndex([['filename', 1]], writeConcern, function() {
      // Get chunk collection
      var chunkCollection = self.chunkCollection();
      // Make an unique index for compatibility with mongo-cxx-driver:legacy
      var chunkIndexOptions = shallowClone(writeConcern);
      chunkIndexOptions.unique = true;
      // Ensure index on chunk collection
      chunkCollection.ensureIndex([['files_id', 1], ['n', 1]], chunkIndexOptions, function() {
        // Open the connection
        _open(self, writeConcern, function(err, r) {
          if (err) return callback(err);
          self.isOpen = true;
          callback(err, r);
        });
      });
    });
  } else {
    // Open the gridstore
    _open(self, writeConcern, function(err, r) {
      if (err) return callback(err);
      self.isOpen = true;
      callback(err, r);
    });
  }
};

/**
 * Verify if the file is at EOF.
 *
 * @method
 * @return {boolean} true if the read/write head is at the end of this file.
 * @deprecated Use GridFSBucket API instead
 */
GridStore.prototype.eof = function() {
  return this.position === this.length ? true : false;
};

/**
 * The callback result format.
 * @callback GridStore~resultCallback
 * @param {object} [options] Optional settings
 * @param {ClientSession} [options.session] optional session to use for this operation
 * @param {MongoError} error An error instance representing the error during the execution.
 * @param {object} result The result from the callback.
 */

/**
 * Retrieves a single character from this file.
 *
 * @method
 * @param {GridStore~resultCallback} [callback] this gets called after this method is executed. Passes null to the first parameter and the character read to the second or null to the second if the read/write head is at the end of the file.
 * @return {Promise} returns Promise if no callback passed
 * @deprecated Use GridFSBucket API instead
 */
GridStore.prototype.getc = function(options, callback) {
  if (typeof options === 'function') (callback = options), (options = {});
  options = options || {};

  return executeOperation(this.db.s.topology, getc, [this, options, callback], {
    skipSessions: true
  });
};

var getc = function(self, options, callback) {
  if (self.eof()) {
    callback(null, null);
  } else if (self.currentChunk.eof()) {
    nthChunk(self, self.currentChunk.chunkNumber + 1, function(err, chunk) {
      self.currentChunk = chunk;
      self.position = self.position + 1;
      callback(err, self.currentChunk.getc());
    });
  } else {
    self.position = self.position + 1;
    callback(null, self.currentChunk.getc());
  }
};

/**
 * Writes a string to the file with a newline character appended at the end if
 * the given string does not have one.
 *
 * @method
 * @param {string} string the string to write.
 * @param {object} [options] Optional settings
 * @param {ClientSession} [options.session] optional session to use for this operation
 * @param {GridStore~resultCallback} [callback] this will be called after executing this method. The first parameter will contain null and the second one will contain a reference to this object.
 * @return {Promise} returns Promise if no callback passed
 * @deprecated Use GridFSBucket API instead
 */
GridStore.prototype.puts = function(string, options, callback) {
  if (typeof options === 'function') (callback = options), (options = {});
  options = options || {};

  var finalString = string.match(/\n$/) == null ? string + '\n' : string;
  return executeOperation(
    this.db.s.topology,
    this.write.bind(this),
    [finalString, options, callback],
    { skipSessions: true }
  );
};

/**
 * Return a modified Readable stream including a possible transform method.
 *
 * @method
 * @return {GridStoreStream}
 * @deprecated Use GridFSBucket API instead
 */
GridStore.prototype.stream = function() {
  return new GridStoreStream(this);
};

/**
 * Writes some data. This method will work properly only if initialized with mode "w" or "w+".
 *
 * @method
 * @param {(string|Buffer)} data the data to write.
 * @param {boolean} [close] closes this file after writing if set to true.
 * @param {object} [options] Optional settings
 * @param {ClientSession} [options.session] optional session to use for this operation
 * @param {GridStore~resultCallback} [callback] this will be called after executing this method. The first parameter will contain null and the second one will contain a reference to this object.
 * @return {Promise} returns Promise if no callback passed
 * @deprecated Use GridFSBucket API instead
 */
GridStore.prototype.write = function write(data, close, options, callback) {
  if (typeof options === 'function') (callback = options), (options = {});
  options = options || {};

  return executeOperation(
    this.db.s.topology,
    _writeNormal,
    [this, data, close, options, callback],
    { skipSessions: true }
  );
};

/**
 * Handles the destroy part of a stream
 *
 * @method
 * @result {null}
 * @deprecated Use GridFSBucket API instead
 */
GridStore.prototype.destroy = function destroy() {
  // close and do not emit any more events. queued data is not sent.
  if (!this.writable) return;
  this.readable = false;
  if (this.writable) {
    this.writable = false;
    this._q.length = 0;
    this.emit('close');
  }
};

/**
 * Stores a file from the file system to the GridFS database.
 *
 * @method
 * @param {(string|Buffer|FileHandle)} file the file to store.
 * @param {object} [options] Optional settings
 * @param {ClientSession} [options.session] optional session to use for this operation
 * @param {GridStore~resultCallback} [callback] this will be called after executing this method. The first parameter will contain null and the second one will contain a reference to this object.
 * @return {Promise} returns Promise if no callback passed
 * @deprecated Use GridFSBucket API instead
 */
GridStore.prototype.writeFile = function(file, options, callback) {
  if (typeof options === 'function') (callback = options), (options = {});
  options = options || {};

  return executeOperation(this.db.s.topology, writeFile, [this, file, options, callback], {
    skipSessions: true
  });
};

var writeFile = function(self, file, options, callback) {
  if (typeof file === 'string') {
    fs.open(file, 'r', function(err, fd) {
      if (err) return callback(err);
      self.writeFile(fd, callback);
    });
    return;
  }

  self.open(function(err, self) {
    if (err) return callback(err, self);

    fs.fstat(file, function(err, stats) {
      if (err) return callback(err, self);

      var offset = 0;
      var index = 0;

      // Write a chunk
      var writeChunk = function() {
        // Allocate the buffer
        var _buffer = Buffer.alloc(self.chunkSize);
        // Read the file
        fs.read(file, _buffer, 0, _buffer.length, offset, function(err, bytesRead, data) {
          if (err) return callback(err, self);

          offset = offset + bytesRead;

          // Create a new chunk for the data
          var chunk = new Chunk(self, { n: index++ }, self.writeConcern);
          chunk.write(data.slice(0, bytesRead), function(err, chunk) {
            if (err) return callback(err, self);

            chunk.save({}, function(err) {
              if (err) return callback(err, self);

              self.position = self.position + bytesRead;

              // Point to current chunk
              self.currentChunk = chunk;

              if (offset >= stats.size) {
                fs.close(file, function(err) {
                  if (err) return callback(err);

                  self.close(function(err) {
                    if (err) return callback(err, self);
                    return callback(null, self);
                  });
                });
              } else {
                return process.nextTick(writeChunk);
              }
            });
          });
        });
      };

      // Process the first write
      process.nextTick(writeChunk);
    });
  });
};

/**
 * Saves this file to the database. This will overwrite the old entry if it
 * already exists. This will work properly only if mode was initialized to
 * "w" or "w+".
 *
 * @method
 * @param {object} [options] Optional settings
 * @param {ClientSession} [options.session] optional session to use for this operation
 * @param {GridStore~resultCallback} [callback] this will be called after executing this method. The first parameter will contain null and the second one will contain a reference to this object.
 * @return {Promise} returns Promise if no callback passed
 * @deprecated Use GridFSBucket API instead
 */
GridStore.prototype.close = function(options, callback) {
  if (typeof options === 'function') (callback = options), (options = {});
  options = options || {};

  return executeOperation(this.db.s.topology, close, [this, options, callback], {
    skipSessions: true
  });
};

var close = function(self, options, callback) {
  if (self.mode[0] === 'w') {
    // Set up options
    options = Object.assign({}, self.writeConcern, options);

    if (self.currentChunk != null &amp;&amp; self.currentChunk.position > 0) {
      self.currentChunk.save({}, function(err) {
        if (err &amp;&amp; typeof callback === 'function') return callback(err);

        self.collection(function(err, files) {
          if (err &amp;&amp; typeof callback === 'function') return callback(err);

          // Build the mongo object
          if (self.uploadDate != null) {
            buildMongoObject(self, function(err, mongoObject) {
              if (err) {
                if (typeof callback === 'function') return callback(err);
                else throw err;
              }

              files.save(mongoObject, options, function(err) {
                if (typeof callback === 'function') callback(err, mongoObject);
              });
            });
          } else {
            self.uploadDate = new Date();
            buildMongoObject(self, function(err, mongoObject) {
              if (err) {
                if (typeof callback === 'function') return callback(err);
                else throw err;
              }

              files.save(mongoObject, options, function(err) {
                if (typeof callback === 'function') callback(err, mongoObject);
              });
            });
          }
        });
      });
    } else {
      self.collection(function(err, files) {
        if (err &amp;&amp; typeof callback === 'function') return callback(err);

        self.uploadDate = new Date();
        buildMongoObject(self, function(err, mongoObject) {
          if (err) {
            if (typeof callback === 'function') return callback(err);
            else throw err;
          }

          files.save(mongoObject, options, function(err) {
            if (typeof callback === 'function') callback(err, mongoObject);
          });
        });
      });
    }
  } else if (self.mode[0] === 'r') {
    if (typeof callback === 'function') callback(null, null);
  } else {
    if (typeof callback === 'function')
      callback(MongoError.create({ message: f('Illegal mode %s', self.mode), driver: true }));
  }
};

/**
 * The collection callback format.
 * @callback GridStore~collectionCallback
 * @param {MongoError} error An error instance representing the error during the execution.
 * @param {Collection} collection The collection from the command execution.
 */

/**
 * Retrieve this file's chunks collection.
 *
 * @method
 * @param {GridStore~collectionCallback} callback the command callback.
 * @return {Collection}
 * @deprecated Use GridFSBucket API instead
 */
GridStore.prototype.chunkCollection = function(callback) {
  if (typeof callback === 'function') return this.db.collection(this.root + '.chunks', callback);
  return this.db.collection(this.root + '.chunks');
};

/**
 * Deletes all the chunks of this file in the database.
 *
 * @method
 * @param {object} [options] Optional settings
 * @param {ClientSession} [options.session] optional session to use for this operation
 * @param {GridStore~resultCallback} [callback] the command callback.
 * @return {Promise} returns Promise if no callback passed
 * @deprecated Use GridFSBucket API instead
 */
GridStore.prototype.unlink = function(options, callback) {
  if (typeof options === 'function') (callback = options), (options = {});
  options = options || {};

  return executeOperation(this.db.s.topology, unlink, [this, options, callback], {
    skipSessions: true
  });
};

var unlink = function(self, options, callback) {
  deleteChunks(self, function(err) {
    if (err !== null) {
      err.message = 'at deleteChunks: ' + err.message;
      return callback(err);
    }

    self.collection(function(err, collection) {
      if (err !== null) {
        err.message = 'at collection: ' + err.message;
        return callback(err);
      }

      collection.remove({ _id: self.fileId }, self.writeConcern, function(err) {
        callback(err, self);
      });
    });
  });
};

/**
 * Retrieves the file collection associated with this object.
 *
 * @method
 * @param {GridStore~collectionCallback} callback the command callback.
 * @return {Collection}
 * @deprecated Use GridFSBucket API instead
 */
GridStore.prototype.collection = function(callback) {
  if (typeof callback === 'function') this.db.collection(this.root + '.files', callback);
  return this.db.collection(this.root + '.files');
};

/**
 * The readlines callback format.
 * @callback GridStore~readlinesCallback
 * @param {MongoError} error An error instance representing the error during the execution.
 * @param {string[]} strings The array of strings returned.
 */

/**
 * Read the entire file as a list of strings splitting by the provided separator.
 *
 * @method
 * @param {string} [separator] The character to be recognized as the newline separator.
 * @param {object} [options] Optional settings
 * @param {ClientSession} [options.session] optional session to use for this operation
 * @param {GridStore~readlinesCallback} [callback] the command callback.
 * @return {Promise} returns Promise if no callback passed
 * @deprecated Use GridFSBucket API instead
 */
GridStore.prototype.readlines = function(separator, options, callback) {
  var args = Array.prototype.slice.call(arguments, 0);
  callback = typeof args[args.length - 1] === 'function' ? args.pop() : undefined;
  separator = args.length ? args.shift() : '\n';
  separator = separator || '\n';
  options = args.length ? args.shift() : {};

  return executeOperation(this.db.s.topology, readlines, [this, separator, options, callback], {
    skipSessions: true
  });
};

var readlines = function(self, separator, options, callback) {
  self.read(function(err, data) {
    if (err) return callback(err);

    var items = data.toString().split(separator);
    items = items.length > 0 ? items.splice(0, items.length - 1) : [];
    for (var i = 0; i &lt; items.length; i++) {
      items[i] = items[i] + separator;
    }

    callback(null, items);
  });
};

/**
 * Deletes all the chunks of this file in the database if mode was set to "w" or
 * "w+" and resets the read/write head to the initial position.
 *
 * @method
 * @param {object} [options] Optional settings
 * @param {ClientSession} [options.session] optional session to use for this operation
 * @param {GridStore~resultCallback} [callback] this will be called after executing this method. The first parameter will contain null and the second one will contain a reference to this object.
 * @return {Promise} returns Promise if no callback passed
 * @deprecated Use GridFSBucket API instead
 */
GridStore.prototype.rewind = function(options, callback) {
  if (typeof options === 'function') (callback = options), (options = {});
  options = options || {};

  return executeOperation(this.db.s.topology, rewind, [this, options, callback], {
    skipSessions: true
  });
};

var rewind = function(self, options, callback) {
  if (self.currentChunk.chunkNumber !== 0) {
    if (self.mode[0] === 'w') {
      deleteChunks(self, function(err) {
        if (err) return callback(err);
        self.currentChunk = new Chunk(self, { n: 0 }, self.writeConcern);
        self.position = 0;
        callback(null, self);
      });
    } else {
      self.currentChunk(0, function(err, chunk) {
        if (err) return callback(err);
        self.currentChunk = chunk;
        self.currentChunk.rewind();
        self.position = 0;
        callback(null, self);
      });
    }
  } else {
    self.currentChunk.rewind();
    self.position = 0;
    callback(null, self);
  }
};

/**
 * The read callback format.
 * @callback GridStore~readCallback
 * @param {MongoError} error An error instance representing the error during the execution.
 * @param {Buffer} data The data read from the GridStore object
 */

/**
 * Retrieves the contents of this file and advances the read/write head. Works with Buffers only.
 *
 * There are 3 signatures for this method:
 *
 * (callback)
 * (length, callback)
 * (length, buffer, callback)
 *
 * @method
 * @param {number} [length] the number of characters to read. Reads all the characters from the read/write head to the EOF if not specified.
 * @param {(string|Buffer)} [buffer] a string to hold temporary data. This is used for storing the string data read so far when recursively calling this method.
 * @param {object} [options] Optional settings
 * @param {ClientSession} [options.session] optional session to use for this operation
 * @param {GridStore~readCallback} [callback] the command callback.
 * @return {Promise} returns Promise if no callback passed
 * @deprecated Use GridFSBucket API instead
 */
GridStore.prototype.read = function(length, buffer, options, callback) {
  var args = Array.prototype.slice.call(arguments, 0);
  callback = typeof args[args.length - 1] === 'function' ? args.pop() : undefined;
  length = args.length ? args.shift() : null;
  buffer = args.length ? args.shift() : null;
  options = args.length ? args.shift() : {};

  return executeOperation(this.db.s.topology, read, [this, length, buffer, options, callback], {
    skipSessions: true
  });
};

var read = function(self, length, buffer, options, callback) {
  // The data is a c-terminated string and thus the length - 1
  var finalLength = length == null ? self.length - self.position : length;
  var finalBuffer = buffer == null ? Buffer.alloc(finalLength) : buffer;
  // Add a index to buffer to keep track of writing position or apply current index
  finalBuffer._index = buffer != null &amp;&amp; buffer._index != null ? buffer._index : 0;

  if (self.currentChunk.length() - self.currentChunk.position + finalBuffer._index >= finalLength) {
    var slice = self.currentChunk.readSlice(finalLength - finalBuffer._index);
    // Copy content to final buffer
    slice.copy(finalBuffer, finalBuffer._index);
    // Update internal position
    self.position = self.position + finalBuffer.length;
    // Check if we don't have a file at all
    if (finalLength === 0 &amp;&amp; finalBuffer.length === 0)
      return callback(MongoError.create({ message: 'File does not exist', driver: true }), null);
    // Else return data
    return callback(null, finalBuffer);
  }

  // Read the next chunk
  slice = self.currentChunk.readSlice(self.currentChunk.length() - self.currentChunk.position);
  // Copy content to final buffer
  slice.copy(finalBuffer, finalBuffer._index);
  // Update index position
  finalBuffer._index += slice.length;

  // Load next chunk and read more
  nthChunk(self, self.currentChunk.chunkNumber + 1, function(err, chunk) {
    if (err) return callback(err);

    if (chunk.length() > 0) {
      self.currentChunk = chunk;
      self.read(length, finalBuffer, callback);
    } else {
      if (finalBuffer._index > 0) {
        callback(null, finalBuffer);
      } else {
        callback(
          MongoError.create({
            message: 'no chunks found for file, possibly corrupt',
            driver: true
          }),
          null
        );
      }
    }
  });
};

/**
 * The tell callback format.
 * @callback GridStore~tellCallback
 * @param {MongoError} error An error instance representing the error during the execution.
 * @param {number} position The current read position in the GridStore.
 */

/**
 * Retrieves the position of the read/write head of this file.
 *
 * @method
 * @param {number} [length] the number of characters to read. Reads all the characters from the read/write head to the EOF if not specified.
 * @param {(string|Buffer)} [buffer] a string to hold temporary data. This is used for storing the string data read so far when recursively calling this method.
 * @param {object} [options] Optional settings
 * @param {ClientSession} [options.session] optional session to use for this operation
 * @param {GridStore~tellCallback} [callback] the command callback.
 * @return {Promise} returns Promise if no callback passed
 * @deprecated Use GridFSBucket API instead
 */
GridStore.prototype.tell = function(callback) {
  var self = this;
  // We provided a callback leg
  if (typeof callback === 'function') return callback(null, this.position);
  // Return promise
  return new self.promiseLibrary(function(resolve) {
    resolve(self.position);
  });
};

/**
 * The tell callback format.
 * @callback GridStore~gridStoreCallback
 * @param {MongoError} error An error instance representing the error during the execution.
 * @param {GridStore} gridStore The gridStore.
 */

/**
 * Moves the read/write head to a new location.
 *
 * There are 3 signatures for this method
 *
 * Seek Location Modes
 *  - **GridStore.IO_SEEK_SET**, **(default)** set the position from the start of the file.
 *  - **GridStore.IO_SEEK_CUR**, set the position from the current position in the file.
 *  - **GridStore.IO_SEEK_END**, set the position from the end of the file.
 *
 * @method
 * @param {number} [position] the position to seek to
 * @param {number} [seekLocation] seek mode. Use one of the Seek Location modes.
 * @param {object} [options] Optional settings
 * @param {ClientSession} [options.session] optional session to use for this operation
 * @param {GridStore~gridStoreCallback} [callback] the command callback.
 * @return {Promise} returns Promise if no callback passed
 * @deprecated Use GridFSBucket API instead
 */
GridStore.prototype.seek = function(position, seekLocation, options, callback) {
  var args = Array.prototype.slice.call(arguments, 1);
  callback = typeof args[args.length - 1] === 'function' ? args.pop() : undefined;
  seekLocation = args.length ? args.shift() : null;
  options = args.length ? args.shift() : {};

  return executeOperation(
    this.db.s.topology,
    seek,
    [this, position, seekLocation, options, callback],
    { skipSessions: true }
  );
};

var seek = function(self, position, seekLocation, options, callback) {
  // Seek only supports read mode
  if (self.mode !== 'r') {
    return callback(
      MongoError.create({ message: 'seek is only supported for mode r', driver: true })
    );
  }

  var seekLocationFinal = seekLocation == null ? GridStore.IO_SEEK_SET : seekLocation;
  var finalPosition = position;
  var targetPosition = 0;

  // Calculate the position
  if (seekLocationFinal === GridStore.IO_SEEK_CUR) {
    targetPosition = self.position + finalPosition;
  } else if (seekLocationFinal === GridStore.IO_SEEK_END) {
    targetPosition = self.length + finalPosition;
  } else {
    targetPosition = finalPosition;
  }

  // Get the chunk
  var newChunkNumber = Math.floor(targetPosition / self.chunkSize);
  var seekChunk = function() {
    nthChunk(self, newChunkNumber, function(err, chunk) {
      if (err) return callback(err, null);
      if (chunk == null) return callback(new Error('no chunk found'));

      // Set the current chunk
      self.currentChunk = chunk;
      self.position = targetPosition;
      self.currentChunk.position = self.position % self.chunkSize;
      callback(err, self);
    });
  };

  seekChunk();
};

/**
 * @ignore
 */
var _open = function(self, options, callback) {
  var collection = self.collection();
  // Create the query
  var query =
    self.referenceBy === REFERENCE_BY_ID ? { _id: self.fileId } : { filename: self.filename };
  query = null == self.fileId &amp;&amp; self.filename == null ? null : query;
  options.readPreference = self.readPreference;

  // Fetch the chunks
  if (query != null) {
    collection.findOne(query, options, function(err, doc) {
      if (err) {
        return error(err);
      }

      // Check if the collection for the files exists otherwise prepare the new one
      if (doc != null) {
        self.fileId = doc._id;
        // Prefer a new filename over the existing one if this is a write
        self.filename =
          self.mode === 'r' || self.filename === undefined ? doc.filename : self.filename;
        self.contentType = doc.contentType;
        self.internalChunkSize = doc.chunkSize;
        self.uploadDate = doc.uploadDate;
        self.aliases = doc.aliases;
        self.length = doc.length;
        self.metadata = doc.metadata;
        self.internalMd5 = doc.md5;
      } else if (self.mode !== 'r') {
        self.fileId = self.fileId == null ? new ObjectID() : self.fileId;
        self.contentType = GridStore.DEFAULT_CONTENT_TYPE;
        self.internalChunkSize =
          self.internalChunkSize == null ? Chunk.DEFAULT_CHUNK_SIZE : self.internalChunkSize;
        self.length = 0;
      } else {
        self.length = 0;
        var txtId = self.fileId._bsontype === 'ObjectID' ? self.fileId.toHexString() : self.fileId;
        return error(
          MongoError.create({
            message: f(
              'file with id %s not opened for writing',
              self.referenceBy === REFERENCE_BY_ID ? txtId : self.filename
            ),
            driver: true
          }),
          self
        );
      }

      // Process the mode of the object
      if (self.mode === 'r') {
        nthChunk(self, 0, options, function(err, chunk) {
          if (err) return error(err);
          self.currentChunk = chunk;
          self.position = 0;
          callback(null, self);
        });
      } else if (self.mode === 'w' &amp;&amp; doc) {
        // Delete any existing chunks
        deleteChunks(self, options, function(err) {
          if (err) return error(err);
          self.currentChunk = new Chunk(self, { n: 0 }, self.writeConcern);
          self.contentType =
            self.options['content_type'] == null ? self.contentType : self.options['content_type'];
          self.internalChunkSize =
            self.options['chunk_size'] == null
              ? self.internalChunkSize
              : self.options['chunk_size'];
          self.metadata =
            self.options['metadata'] == null ? self.metadata : self.options['metadata'];
          self.aliases = self.options['aliases'] == null ? self.aliases : self.options['aliases'];
          self.position = 0;
          callback(null, self);
        });
      } else if (self.mode === 'w') {
        self.currentChunk = new Chunk(self, { n: 0 }, self.writeConcern);
        self.contentType =
          self.options['content_type'] == null ? self.contentType : self.options['content_type'];
        self.internalChunkSize =
          self.options['chunk_size'] == null ? self.internalChunkSize : self.options['chunk_size'];
        self.metadata = self.options['metadata'] == null ? self.metadata : self.options['metadata'];
        self.aliases = self.options['aliases'] == null ? self.aliases : self.options['aliases'];
        self.position = 0;
        callback(null, self);
      } else if (self.mode === 'w+') {
        nthChunk(self, lastChunkNumber(self), options, function(err, chunk) {
          if (err) return error(err);
          // Set the current chunk
          self.currentChunk = chunk == null ? new Chunk(self, { n: 0 }, self.writeConcern) : chunk;
          self.currentChunk.position = self.currentChunk.data.length();
          self.metadata =
            self.options['metadata'] == null ? self.metadata : self.options['metadata'];
          self.aliases = self.options['aliases'] == null ? self.aliases : self.options['aliases'];
          self.position = self.length;
          callback(null, self);
        });
      }
    });
  } else {
    // Write only mode
    self.fileId = null == self.fileId ? new ObjectID() : self.fileId;
    self.contentType = GridStore.DEFAULT_CONTENT_TYPE;
    self.internalChunkSize =
      self.internalChunkSize == null ? Chunk.DEFAULT_CHUNK_SIZE : self.internalChunkSize;
    self.length = 0;

    // No file exists set up write mode
    if (self.mode === 'w') {
      // Delete any existing chunks
      deleteChunks(self, options, function(err) {
        if (err) return error(err);
        self.currentChunk = new Chunk(self, { n: 0 }, self.writeConcern);
        self.contentType =
          self.options['content_type'] == null ? self.contentType : self.options['content_type'];
        self.internalChunkSize =
          self.options['chunk_size'] == null ? self.internalChunkSize : self.options['chunk_size'];
        self.metadata = self.options['metadata'] == null ? self.metadata : self.options['metadata'];
        self.aliases = self.options['aliases'] == null ? self.aliases : self.options['aliases'];
        self.position = 0;
        callback(null, self);
      });
    } else if (self.mode === 'w+') {
      nthChunk(self, lastChunkNumber(self), options, function(err, chunk) {
        if (err) return error(err);
        // Set the current chunk
        self.currentChunk = chunk == null ? new Chunk(self, { n: 0 }, self.writeConcern) : chunk;
        self.currentChunk.position = self.currentChunk.data.length();
        self.metadata = self.options['metadata'] == null ? self.metadata : self.options['metadata'];
        self.aliases = self.options['aliases'] == null ? self.aliases : self.options['aliases'];
        self.position = self.length;
        callback(null, self);
      });
    }
  }

  // only pass error to callback once
  function error(err) {
    if (error.err) return;
    callback((error.err = err));
  }
};

/**
 * @ignore
 */
var writeBuffer = function(self, buffer, close, callback) {
  if (typeof close === 'function') {
    callback = close;
    close = null;
  }
  var finalClose = typeof close === 'boolean' ? close : false;

  if (self.mode !== 'w') {
    callback(
      MongoError.create({
        message: f(
          'file with id %s not opened for writing',
          self.referenceBy === REFERENCE_BY_ID ? self.referenceBy : self.filename
        ),
        driver: true
      }),
      null
    );
  } else {
    if (self.currentChunk.position + buffer.length >= self.chunkSize) {
      // Write out the current Chunk and then keep writing until we have less data left than a chunkSize left
      // to a new chunk (recursively)
      var previousChunkNumber = self.currentChunk.chunkNumber;
      var leftOverDataSize = self.chunkSize - self.currentChunk.position;
      var firstChunkData = buffer.slice(0, leftOverDataSize);
      var leftOverData = buffer.slice(leftOverDataSize);
      // A list of chunks to write out
      var chunksToWrite = [self.currentChunk.write(firstChunkData)];
      // If we have more data left than the chunk size let's keep writing new chunks
      while (leftOverData.length >= self.chunkSize) {
        // Create a new chunk and write to it
        var newChunk = new Chunk(self, { n: previousChunkNumber + 1 }, self.writeConcern);
        firstChunkData = leftOverData.slice(0, self.chunkSize);
        leftOverData = leftOverData.slice(self.chunkSize);
        // Update chunk number
        previousChunkNumber = previousChunkNumber + 1;
        // Write data
        newChunk.write(firstChunkData);
        // Push chunk to save list
        chunksToWrite.push(newChunk);
      }

      // Set current chunk with remaining data
      self.currentChunk = new Chunk(self, { n: previousChunkNumber + 1 }, self.writeConcern);
      // If we have left over data write it
      if (leftOverData.length > 0) self.currentChunk.write(leftOverData);

      // Update the position for the gridstore
      self.position = self.position + buffer.length;
      // Total number of chunks to write
      var numberOfChunksToWrite = chunksToWrite.length;

      for (var i = 0; i &lt; chunksToWrite.length; i++) {
        chunksToWrite[i].save({}, function(err) {
          if (err) return callback(err);

          numberOfChunksToWrite = numberOfChunksToWrite - 1;

          if (numberOfChunksToWrite &lt;= 0) {
            // We care closing the file before returning
            if (finalClose) {
              return self.close(function(err) {
                callback(err, self);
              });
            }

            // Return normally
            return callback(null, self);
          }
        });
      }
    } else {
      // Update the position for the gridstore
      self.position = self.position + buffer.length;
      // We have less data than the chunk size just write it and callback
      self.currentChunk.write(buffer);
      // We care closing the file before returning
      if (finalClose) {
        return self.close(function(err) {
          callback(err, self);
        });
      }
      // Return normally
      return callback(null, self);
    }
  }
};

/**
 * Creates a mongoDB object representation of this object.
 *
 *        &lt;pre>&lt;code>
 *        {
 *          '_id' : , // {number} id for this file
 *          'filename' : , // {string} name for this file
 *          'contentType' : , // {string} mime type for this file
 *          'length' : , // {number} size of this file?
 *          'chunksize' : , // {number} chunk size used by this file
 *          'uploadDate' : , // {Date}
 *          'aliases' : , // {array of string}
 *          'metadata' : , // {string}
 *        }
 *        &lt;/code>&lt;/pre>
 *
 * @ignore
 */
var buildMongoObject = function(self, callback) {
  // Calcuate the length
  var mongoObject = {
    _id: self.fileId,
    filename: self.filename,
    contentType: self.contentType,
    length: self.position ? self.position : 0,
    chunkSize: self.chunkSize,
    uploadDate: self.uploadDate,
    aliases: self.aliases,
    metadata: self.metadata
  };

  var md5Command = { filemd5: self.fileId, root: self.root };
  self.db.command(md5Command, function(err, results) {
    if (err) return callback(err);

    mongoObject.md5 = results.md5;
    callback(null, mongoObject);
  });
};

/**
 * Gets the nth chunk of this file.
 * @ignore
 */
var nthChunk = function(self, chunkNumber, options, callback) {
  if (typeof options === 'function') {
    callback = options;
    options = {};
  }

  options = options || self.writeConcern;
  options.readPreference = self.readPreference;
  // Get the nth chunk
  self
    .chunkCollection()
    .findOne({ files_id: self.fileId, n: chunkNumber }, options, function(err, chunk) {
      if (err) return callback(err);

      var finalChunk = chunk == null ? {} : chunk;
      callback(null, new Chunk(self, finalChunk, self.writeConcern));
    });
};

/**
 * @ignore
 */
var lastChunkNumber = function(self) {
  return Math.floor((self.length ? self.length - 1 : 0) / self.chunkSize);
};

/**
 * Deletes all the chunks of this file in the database.
 *
 * @ignore
 */
var deleteChunks = function(self, options, callback) {
  if (typeof options === 'function') {
    callback = options;
    options = {};
  }

  options = options || self.writeConcern;

  if (self.fileId != null) {
    self.chunkCollection().remove({ files_id: self.fileId }, options, function(err) {
      if (err) return callback(err, false);
      callback(null, true);
    });
  } else {
    callback(null, true);
  }
};

/**
 * The collection to be used for holding the files and chunks collection.
 *
 * @classconstant DEFAULT_ROOT_COLLECTION
 */
GridStore.DEFAULT_ROOT_COLLECTION = 'fs';

/**
 * Default file mime type
 *
 * @classconstant DEFAULT_CONTENT_TYPE
 */
GridStore.DEFAULT_CONTENT_TYPE = 'binary/octet-stream';

/**
 * Seek mode where the given length is absolute.
 *
 * @classconstant IO_SEEK_SET
 */
GridStore.IO_SEEK_SET = 0;

/**
 * Seek mode where the given length is an offset to the current read/write head.
 *
 * @classconstant IO_SEEK_CUR
 */
GridStore.IO_SEEK_CUR = 1;

/**
 * Seek mode where the given length is an offset to the end of the file.
 *
 * @classconstant IO_SEEK_END
 */
GridStore.IO_SEEK_END = 2;

/**
 * Checks if a file exists in the database.
 *
 * @method
 * @static
 * @param {Db} db the database to query.
 * @param {string} name The name of the file to look for.
 * @param {string} [rootCollection] The root collection that holds the files and chunks collection. Defaults to **{GridStore.DEFAULT_ROOT_COLLECTION}**.
 * @param {object} [options] Optional settings.
 * @param {(ReadPreference|string)} [options.readPreference] The preferred read preference (ReadPreference.PRIMARY, ReadPreference.PRIMARY_PREFERRED, ReadPreference.SECONDARY, ReadPreference.SECONDARY_PREFERRED, ReadPreference.NEAREST).
 * @param {object} [options.promiseLibrary] A Promise library class the application wishes to use such as Bluebird, must be ES6 compatible
 * @param {ClientSession} [options.session] optional session to use for this operation
 * @param {GridStore~resultCallback} [callback] result from exists.
 * @return {Promise} returns Promise if no callback passed
 * @deprecated Use GridFSBucket API instead
 */
GridStore.exist = function(db, fileIdObject, rootCollection, options, callback) {
  var args = Array.prototype.slice.call(arguments, 2);
  callback = typeof args[args.length - 1] === 'function' ? args.pop() : undefined;
  rootCollection = args.length ? args.shift() : null;
  options = args.length ? args.shift() : {};
  options = options || {};

  return executeOperation(
    db.s.topology,
    exists,
    [db, fileIdObject, rootCollection, options, callback],
    { skipSessions: true }
  );
};

var exists = function(db, fileIdObject, rootCollection, options, callback) {
  // Establish read preference
  var readPreference = options.readPreference || ReadPreference.PRIMARY;
  // Fetch collection
  var rootCollectionFinal =
    rootCollection != null ? rootCollection : GridStore.DEFAULT_ROOT_COLLECTION;
  db.collection(rootCollectionFinal + '.files', function(err, collection) {
    if (err) return callback(err);

    // Build query
    var query =
      typeof fileIdObject === 'string' ||
      Object.prototype.toString.call(fileIdObject) === '[object RegExp]'
        ? { filename: fileIdObject }
        : { _id: fileIdObject }; // Attempt to locate file

    // We have a specific query
    if (
      fileIdObject != null &amp;&amp;
      typeof fileIdObject === 'object' &amp;&amp;
      Object.prototype.toString.call(fileIdObject) !== '[object RegExp]'
    ) {
      query = fileIdObject;
    }

    // Check if the entry exists
    collection.findOne(query, { readPreference: readPreference }, function(err, item) {
      if (err) return callback(err);
      callback(null, item == null ? false : true);
    });
  });
};

/**
 * Gets the list of files stored in the GridFS.
 *
 * @method
 * @static
 * @param {Db} db the database to query.
 * @param {string} [rootCollection] The root collection that holds the files and chunks collection. Defaults to **{GridStore.DEFAULT_ROOT_COLLECTION}**.
 * @param {object} [options] Optional settings.
 * @param {(ReadPreference|string)} [options.readPreference] The preferred read preference (ReadPreference.PRIMARY, ReadPreference.PRIMARY_PREFERRED, ReadPreference.SECONDARY, ReadPreference.SECONDARY_PREFERRED, ReadPreference.NEAREST).
 * @param {object} [options.promiseLibrary] A Promise library class the application wishes to use such as Bluebird, must be ES6 compatible
 * @param {ClientSession} [options.session] optional session to use for this operation
 * @param {GridStore~resultCallback} [callback] result from exists.
 * @return {Promise} returns Promise if no callback passed
 * @deprecated Use GridFSBucket API instead
 */
GridStore.list = function(db, rootCollection, options, callback) {
  var args = Array.prototype.slice.call(arguments, 1);
  callback = typeof args[args.length - 1] === 'function' ? args.pop() : undefined;
  rootCollection = args.length ? args.shift() : null;
  options = args.length ? args.shift() : {};
  options = options || {};

  return executeOperation(db.s.topology, list, [db, rootCollection, options, callback], {
    skipSessions: true
  });
};

var list = function(db, rootCollection, options, callback) {
  // Ensure we have correct values
  if (rootCollection != null &amp;&amp; typeof rootCollection === 'object') {
    options = rootCollection;
    rootCollection = null;
  }

  // Establish read preference
  var readPreference = options.readPreference || ReadPreference.primary;
  // Check if we are returning by id not filename
  var byId = options['id'] != null ? options['id'] : false;
  // Fetch item
  var rootCollectionFinal =
    rootCollection != null ? rootCollection : GridStore.DEFAULT_ROOT_COLLECTION;
  var items = [];
  db.collection(rootCollectionFinal + '.files', function(err, collection) {
    if (err) return callback(err);

    collection.find({}, { readPreference: readPreference }, function(err, cursor) {
      if (err) return callback(err);

      cursor.each(function(err, item) {
        if (item != null) {
          items.push(byId ? item._id : item.filename);
        } else {
          callback(err, items);
        }
      });
    });
  });
};

/**
 * Reads the contents of a file.
 *
 * This method has the following signatures
 *
 * (db, name, callback)
 * (db, name, length, callback)
 * (db, name, length, offset, callback)
 * (db, name, length, offset, options, callback)
 *
 * @method
 * @static
 * @param {Db} db the database to query.
 * @param {string} name The name of the file.
 * @param {number} [length] The size of data to read.
 * @param {number} [offset] The offset from the head of the file of which to start reading from.
 * @param {object} [options] Optional settings.
 * @param {(ReadPreference|string)} [options.readPreference] The preferred read preference (ReadPreference.PRIMARY, ReadPreference.PRIMARY_PREFERRED, ReadPreference.SECONDARY, ReadPreference.SECONDARY_PREFERRED, ReadPreference.NEAREST).
 * @param {object} [options.promiseLibrary] A Promise library class the application wishes to use such as Bluebird, must be ES6 compatible
 * @param {ClientSession} [options.session] optional session to use for this operation
 * @param {GridStore~readCallback} [callback] the command callback.
 * @return {Promise} returns Promise if no callback passed
 * @deprecated Use GridFSBucket API instead
 */
GridStore.read = function(db, name, length, offset, options, callback) {
  var args = Array.prototype.slice.call(arguments, 2);
  callback = typeof args[args.length - 1] === 'function' ? args.pop() : undefined;
  length = args.length ? args.shift() : null;
  offset = args.length ? args.shift() : null;
  options = args.length ? args.shift() : null;
  options = options || {};

  return executeOperation(
    db.s.topology,
    readStatic,
    [db, name, length, offset, options, callback],
    { skipSessions: true }
  );
};

var readStatic = function(db, name, length, offset, options, callback) {
  new GridStore(db, name, 'r', options).open(function(err, gridStore) {
    if (err) return callback(err);
    // Make sure we are not reading out of bounds
    if (offset &amp;&amp; offset >= gridStore.length)
      return callback('offset larger than size of file', null);
    if (length &amp;&amp; length > gridStore.length)
      return callback('length is larger than the size of the file', null);
    if (offset &amp;&amp; length &amp;&amp; offset + length > gridStore.length)
      return callback('offset and length is larger than the size of the file', null);

    if (offset != null) {
      gridStore.seek(offset, function(err, gridStore) {
        if (err) return callback(err);
        gridStore.read(length, callback);
      });
    } else {
      gridStore.read(length, callback);
    }
  });
};

/**
 * Read the entire file as a list of strings splitting by the provided separator.
 *
 * @method
 * @static
 * @param {Db} db the database to query.
 * @param {(String|object)} name the name of the file.
 * @param {string} [separator] The character to be recognized as the newline separator.
 * @param {object} [options] Optional settings.
 * @param {(ReadPreference|string)} [options.readPreference] The preferred read preference (ReadPreference.PRIMARY, ReadPreference.PRIMARY_PREFERRED, ReadPreference.SECONDARY, ReadPreference.SECONDARY_PREFERRED, ReadPreference.NEAREST).
 * @param {object} [options.promiseLibrary] A Promise library class the application wishes to use such as Bluebird, must be ES6 compatible
 * @param {ClientSession} [options.session] optional session to use for this operation
 * @param {GridStore~readlinesCallback} [callback] the command callback.
 * @return {Promise} returns Promise if no callback passed
 * @deprecated Use GridFSBucket API instead
 */
GridStore.readlines = function(db, name, separator, options, callback) {
  var args = Array.prototype.slice.call(arguments, 2);
  callback = typeof args[args.length - 1] === 'function' ? args.pop() : undefined;
  separator = args.length ? args.shift() : null;
  options = args.length ? args.shift() : null;
  options = options || {};

  return executeOperation(
    db.s.topology,
    readlinesStatic,
    [db, name, separator, options, callback],
    { skipSessions: true }
  );
};

var readlinesStatic = function(db, name, separator, options, callback) {
  var finalSeperator = separator == null ? '\n' : separator;
  new GridStore(db, name, 'r', options).open(function(err, gridStore) {
    if (err) return callback(err);
    gridStore.readlines(finalSeperator, callback);
  });
};

/**
 * Deletes the chunks and metadata information of a file from GridFS.
 *
 * @method
 * @static
 * @param {Db} db The database to query.
 * @param {(string|array)} names The name/names of the files to delete.
 * @param {object} [options] Optional settings.
 * @param {object} [options.promiseLibrary] A Promise library class the application wishes to use such as Bluebird, must be ES6 compatible
 * @param {ClientSession} [options.session] optional session to use for this operation
 * @param {GridStore~resultCallback} [callback] the command callback.
 * @return {Promise} returns Promise if no callback passed
 * @deprecated Use GridFSBucket API instead
 */
GridStore.unlink = function(db, names, options, callback) {
  var args = Array.prototype.slice.call(arguments, 2);
  callback = typeof args[args.length - 1] === 'function' ? args.pop() : undefined;
  options = args.length ? args.shift() : {};
  options = options || {};

  return executeOperation(db.s.topology, unlinkStatic, [this, db, names, options, callback], {
    skipSessions: true
  });
};

var unlinkStatic = function(self, db, names, options, callback) {
  // Get the write concern
  var writeConcern = _getWriteConcern(db, options);

  // List of names
  if (names.constructor === Array) {
    var tc = 0;
    for (var i = 0; i &lt; names.length; i++) {
      ++tc;
      GridStore.unlink(db, names[i], options, function() {
        if (--tc === 0) {
          callback(null, self);
        }
      });
    }
  } else {
    new GridStore(db, names, 'w', options).open(function(err, gridStore) {
      if (err) return callback(err);
      deleteChunks(gridStore, function(err) {
        if (err) return callback(err);
        gridStore.collection(function(err, collection) {
          if (err) return callback(err);
          collection.remove({ _id: gridStore.fileId }, writeConcern, function(err) {
            callback(err, self);
          });
        });
      });
    });
  }
};

/**
 *  @ignore
 */
var _writeNormal = function(self, data, close, options, callback) {
  // If we have a buffer write it using the writeBuffer method
  if (Buffer.isBuffer(data)) {
    return writeBuffer(self, data, close, callback);
  } else {
    return writeBuffer(self, Buffer.from(data, 'binary'), close, callback);
  }
};

/**
 * @ignore
 */
var _setWriteConcernHash = function(options) {
  var finalOptions = {};
  if (options.w != null) finalOptions.w = options.w;
  if (options.journal === true) finalOptions.j = options.journal;
  if (options.j === true) finalOptions.j = options.j;
  if (options.fsync === true) finalOptions.fsync = options.fsync;
  if (options.wtimeout != null) finalOptions.wtimeout = options.wtimeout;
  return finalOptions;
};

/**
 * @ignore
 */
var _getWriteConcern = function(self, options) {
  // Final options
  var finalOptions = { w: 1 };
  options = options || {};

  // Local options verification
  if (
    options.w != null ||
    typeof options.j === 'boolean' ||
    typeof options.journal === 'boolean' ||
    typeof options.fsync === 'boolean'
  ) {
    finalOptions = _setWriteConcernHash(options);
  } else if (options.safe != null &amp;&amp; typeof options.safe === 'object') {
    finalOptions = _setWriteConcernHash(options.safe);
  } else if (typeof options.safe === 'boolean') {
    finalOptions = { w: options.safe ? 1 : 0 };
  } else if (
    self.options.w != null ||
    typeof self.options.j === 'boolean' ||
    typeof self.options.journal === 'boolean' ||
    typeof self.options.fsync === 'boolean'
  ) {
    finalOptions = _setWriteConcernHash(self.options);
  } else if (
    self.safe &amp;&amp;
    (self.safe.w != null ||
      typeof self.safe.j === 'boolean' ||
      typeof self.safe.journal === 'boolean' ||
      typeof self.safe.fsync === 'boolean')
  ) {
    finalOptions = _setWriteConcernHash(self.safe);
  } else if (typeof self.safe === 'boolean') {
    finalOptions = { w: self.safe ? 1 : 0 };
  }

  // Ensure we don't have an invalid combination of write concerns
  if (
    finalOptions.w &lt; 1 &amp;&amp;
    (finalOptions.journal === true || finalOptions.j === true || finalOptions.fsync === true)
  )
    throw MongoError.create({
      message: 'No acknowledgement using w &lt; 1 cannot be combined with journal:true or fsync:true',
      driver: true
    });

  // Return the options
  return finalOptions;
};

/**
 * Create a new GridStoreStream instance (INTERNAL TYPE, do not instantiate directly)
 *
 * @class
 * @extends external:Duplex
 * @return {GridStoreStream} a GridStoreStream instance.
 * @deprecated Use GridFSBucket API instead
 */
var GridStoreStream = function(gs) {
  // Initialize the duplex stream
  Duplex.call(this);

  // Get the gridstore
  this.gs = gs;

  // End called
  this.endCalled = false;

  // If we have a seek
  this.totalBytesToRead = this.gs.length - this.gs.position;
  this.seekPosition = this.gs.position;
};

//
// Inherit duplex
inherits(GridStoreStream, Duplex);

GridStoreStream.prototype._pipe = GridStoreStream.prototype.pipe;

// Set up override
GridStoreStream.prototype.pipe = function(destination) {
  var self = this;

  // Only open gridstore if not already open
  if (!self.gs.isOpen) {
    self.gs.open(function(err) {
      if (err) return self.emit('error', err);
      self.totalBytesToRead = self.gs.length - self.gs.position;
      self._pipe.apply(self, [destination]);
    });
  } else {
    self.totalBytesToRead = self.gs.length - self.gs.position;
    self._pipe.apply(self, [destination]);
  }

  return destination;
};

// Called by stream
GridStoreStream.prototype._read = function() {
  var self = this;

  var read = function() {
    // Read data
    self.gs.read(length, function(err, buffer) {
      if (err &amp;&amp; !self.endCalled) return self.emit('error', err);

      // Stream is closed
      if (self.endCalled || buffer == null) return self.push(null);
      // Remove bytes read
      if (buffer.length &lt;= self.totalBytesToRead) {
        self.totalBytesToRead = self.totalBytesToRead - buffer.length;
        self.push(buffer);
      } else if (buffer.length > self.totalBytesToRead) {
        self.totalBytesToRead = self.totalBytesToRead - buffer._index;
        self.push(buffer.slice(0, buffer._index));
      }

      // Finished reading
      if (self.totalBytesToRead &lt;= 0) {
        self.endCalled = true;
      }
    });
  };

  // Set read length
  var length =
    self.gs.length &lt; self.gs.chunkSize ? self.gs.length - self.seekPosition : self.gs.chunkSize;
  if (!self.gs.isOpen) {
    self.gs.open(function(err) {
      self.totalBytesToRead = self.gs.length - self.gs.position;
      if (err) return self.emit('error', err);
      read();
    });
  } else {
    read();
  }
};

GridStoreStream.prototype.destroy = function() {
  this.pause();
  this.endCalled = true;
  this.gs.close();
  this.emit('end');
};

GridStoreStream.prototype.write = function(chunk) {
  var self = this;
  if (self.endCalled)
    return self.emit(
      'error',
      MongoError.create({ message: 'attempting to write to stream after end called', driver: true })
    );
  // Do we have to open the gridstore
  if (!self.gs.isOpen) {
    self.gs.open(function() {
      self.gs.isOpen = true;
      self.gs.write(chunk, function() {
        process.nextTick(function() {
          self.emit('drain');
        });
      });
    });
    return false;
  } else {
    self.gs.write(chunk, function() {
      self.emit('drain');
    });
    return true;
  }
};

GridStoreStream.prototype.end = function(chunk, encoding, callback) {
  var self = this;
  var args = Array.prototype.slice.call(arguments, 0);
  callback = typeof args[args.length - 1] === 'function' ? args.pop() : undefined;
  chunk = args.length ? args.shift() : null;
  encoding = args.length ? args.shift() : null;
  self.endCalled = true;

  if (chunk) {
    self.gs.write(chunk, function() {
      self.gs.close(function() {
        if (typeof callback === 'function') callback();
        self.emit('end');
      });
    });
  }

  self.gs.close(function() {
    if (typeof callback === 'function') callback();
    self.emit('end');
  });
};

/**
 * The read() method pulls some data out of the internal buffer and returns it. If there is no data available, then it will return null.
 * @function external:Duplex#read
 * @param {number} size Optional argument to specify how much data to read.
 * @return {(String | Buffer | null)}
 */

/**
 * Call this function to cause the stream to return strings of the specified encoding instead of Buffer objects.
 * @function external:Duplex#setEncoding
 * @param {string} encoding The encoding to use.
 * @return {null}
 */

/**
 * This method will cause the readable stream to resume emitting data events.
 * @function external:Duplex#resume
 * @return {null}
 */

/**
 * This method will cause a stream in flowing-mode to stop emitting data events. Any data that becomes available will remain in the internal buffer.
 * @function external:Duplex#pause
 * @return {null}
 */

/**
 * This method pulls all the data out of a readable stream, and writes it to the supplied destination, automatically managing the flow so that the destination is not overwhelmed by a fast readable stream.
 * @function external:Duplex#pipe
 * @param {Writable} destination The destination for writing data
 * @param {object} [options] Pipe options
 * @return {null}
 */

/**
 * This method will remove the hooks set up for a previous pipe() call.
 * @function external:Duplex#unpipe
 * @param {Writable} [destination] The destination for writing data
 * @return {null}
 */

/**
 * This is useful in certain cases where a stream is being consumed by a parser, which needs to "un-consume" some data that it has optimistically pulled out of the source, so that the stream can be passed on to some other party.
 * @function external:Duplex#unshift
 * @param {(Buffer|string)} chunk Chunk of data to unshift onto the read queue.
 * @return {null}
 */

/**
 * Versions of Node prior to v0.10 had streams that did not implement the entire Streams API as it is today. (See "Compatibility" below for more information.)
 * @function external:Duplex#wrap
 * @param {Stream} stream An "old style" readable stream.
 * @return {null}
 */

/**
 * This method writes some data to the underlying system, and calls the supplied callback once the data has been fully handled.
 * @function external:Duplex#write
 * @param {(string|Buffer)} chunk The data to write
 * @param {string} encoding The encoding, if chunk is a String
 * @param {function} callback Callback for when this chunk of data is flushed
 * @return {boolean}
 */

/**
 * Call this method when no more data will be written to the stream. If supplied, the callback is attached as a listener on the finish event.
 * @function external:Duplex#end
 * @param {(string|Buffer)} chunk The data to write
 * @param {string} encoding The encoding, if chunk is a String
 * @param {function} callback Callback for when this chunk of data is flushed
 * @return {null}
 */

/**
 * GridStoreStream stream data event, fired for each document in the cursor.
 *
 * @event GridStoreStream#data
 * @type {object}
 */

/**
 * GridStoreStream stream end event
 *
 * @event GridStoreStream#end
 * @type {null}
 */

/**
 * GridStoreStream stream close event
 *
 * @event GridStoreStream#close
 * @type {null}
 */

/**
 * GridStoreStream stream readable event
 *
 * @event GridStoreStream#readable
 * @type {null}
 */

/**
 * GridStoreStream stream drain event
 *
 * @event GridStoreStream#drain
 * @type {null}
 */

/**
 * GridStoreStream stream finish event
 *
 * @event GridStoreStream#finish
 * @type {null}
 */

/**
 * GridStoreStream stream pipe event
 *
 * @event GridStoreStream#pipe
 * @type {null}
 */

/**
 * GridStoreStream stream unpipe event
 *
 * @event GridStoreStream#unpipe
 * @type {null}
 */

/**
 * GridStoreStream stream error event
 *
 * @event GridStoreStream#error
 * @type {null}
 */

/**
 * @ignore
 */
module.exports = GridStore;
</code></pre>
        </article>
    </section>






                    <footer>
                        Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.6</a> on Wed Jan 20 2021 10:00:47 GMT-0500 (Eastern Standard Time)
                    </footer>
                </div>
            </td>
        </tr>
    </table>
</div>
<script>prettyPrint();</script>
<script src="scripts/linenumber.js"></script>
<script src="scripts/main.js"></script>
</body>
</html>
